text.devel_generate.inc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. function text_devel_generate($object, $field, $instance, $bundle) {
  3. if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
  4. return devel_generate_multiple('_text_devel_generate', $object, $field, $instance, $bundle);
  5. }
  6. else {
  7. return _text_devel_generate($object, $field, $instance, $bundle);
  8. }
  9. }
  10. function _text_devel_generate($object, $field, $instance, $bundle) {
  11. $object_field = array();
  12. if (!empty($instance['settings']['text_processing'])) {
  13. $formats = filter_formats();
  14. $format = array_rand($formats);
  15. }
  16. else {
  17. $format = filter_fallback_format();
  18. }
  19. if ($instance['widget']['type'] != 'text_textfield') {
  20. // Textarea handling
  21. $object_field['value'] = devel_create_content($format);
  22. if ($instance['widget']['type'] == 'text_textarea_with_summary' && !empty($instance['display_summary'])) {
  23. $object_field['summary'] = devel_create_content($format);
  24. }
  25. }
  26. else {
  27. // Textfield handling.
  28. // Generate a value that respects max_length.
  29. if (empty($field['settings']['max_length'])) {
  30. $field['settings']['max_length'] = 12;
  31. }
  32. $object_field['value'] = user_password($field['settings']['max_length']);
  33. }
  34. $object_field['format'] = $format;
  35. return $object_field;
  36. }