Currently, the module generates long text for text fields like this:
YYvM78jcoXCm4sHuQivbUEuvBqhJzg3bUFwKMNrWEr8p6kgB6KR3u2

which isn't terrible useful, because the long text can break layouts.

Currently, the code can be found in /includes/content.devel.inc

I recommend substituting this line of code within the _text_content_generate() function:

$node_field['value'] = user_password($field['max_length']);

With this:
$node_field['value'] = devel_create_greeking(mt_rand(1, $field['max_length']));

which creates a nice greek title, of some random length between 1 and the maximum length of the field.

Patch is attached.


function _text_content_generate($node, $field) {
    $node_field = array();
    if ($field['widget']['type'] == 'text_textarea') {
      $format = $field['text_processing'] ? rand(0, 3) : 0;
      $node_field['value'] = devel_create_content($format);
      $node_field['format'] = $format;
    }
    else {
      $allowed_values = content_allowed_values($field);
      if (!empty($allowed_values)) {
        // Just pick one of the specified allowed values.
        $node_field['value'] = array_rand($allowed_values);
      }
      else {
        // Generate a value that respects max_length.
        if (empty($field['max_length'])) {
          $field['max_length'] = 12;
        }
        $node_field['value'] = devel_create_greeking(mt_rand(1, $field['max_length']));
      }
    }
    return $node_field;
  }

Comments

Mac Clemmens’s picture

StatusFileSize
new1.08 KB

Here's an improved version. I didn't realize the length needed to be specified in number of words, not number of characters.

If it's shorter than or equal to a maxlength of 12 characters, it still uses the user_password function the length of the field. But if it's longer, it makes a nice greek title. If it's really long, it makes a paragraph.

Updated patch attached.

--- content.devel.inc (saved version)
+++ (current document)
@@ -116,9 +116,20 @@
       else {
         // Generate a value that respects max_length.
         if (empty($field['max_length'])) {
-          $field['max_length'] = 12;
+          $field['max_length'] = 24;
+        }
+        if ($field['max_length'] < 12) {
+          // Make a short text string, e.g. 230sdio23h4
+          $node_field['value'] = user_password($field['max_length']);
+        }
+        elseif ($field['max_length'] < 36) {
+          // Make a short title, e.g. Commodo Abico Paratus Aptent Defui Letalis Mos Os
+          $node_field['value'] = substr(devel_create_greeking(mt_rand(1, $field['max_length'] / 6), TRUE), 0, $field['max_length']);
+        }
+        else {
+          // Make a short sentence, e.g. Quidne dolor ad quibus similis commoveo virtus ibidem. Singularis acsi acsi distineo.
+          $node_field['value'] = substr(devel_create_greeking(mt_rand(1, $field['max_length'] / 6), FALSE), 0, $field['max_length']);
         }
-        $node_field['value'] = user_password($field['max_length']);
       }
     }
     return $node_field;

gagarine’s picture

Title: Improving the usefulness of devel generated text » Use devel_create_greeking for text field instead of user_password
Project: Content Construction Kit (CCK) » Devel
Version: 6.x-2.x-dev » 7.x-1.x-dev
Component: Usability » devel_generate
Category: task » feature
Status: Needs review » Needs work

This is in text.devel_generate.inc in the devel module now.

+1 for this feature

salvis’s picture

rickvug’s picture

Status: Needs work » Needs review
StatusFileSize
new707 bytes

Attached is an initial patch updated to D7. It does not include the additional logic based on the length of the field.

brenes’s picture

Great, thank you for your patch. Applied against Devel 7.x-1.0 and it works as described in #4.

salvis’s picture

So, should we commit this "initial patch" or do we wait for an improved version?

tauno’s picture

The initial patch does what it says and seems to be an improvement over the current behavior. Seems like more customized behavior could ultimately be handled by #1326204: Allow field generate function to be alterable, if it gets committed.

Countzero’s picture

Tried the patch in #4 : content looks really nicer. Thanks a lot.

afmdsouza’s picture

Applied patch at #4 on the latest dev version, works fine. Thanks for the patch!

salvis’s picture

So what do we do with #4

It does not include the additional logic based on the length of the field.

?

dkingofpa’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #4 fixes the issue of the long unbroken password text generated for text fields. It doesn't include the logic for generating different text lengths based on the max-length of the field. I don't think that logic is necessary to get this patch committed. Layouts are being broken with devel generated text right now! :)

moshe weitzman’s picture

Status: Reviewed & tested by the community » Active

Committed #4 to 7.x and 8.x. Leaving open for Field issue.

willzyx’s picture

Status: Active » Closed (outdated)

Closing for lack of activity. Feel free to reopen if the issue still exists