Search form

Drupal 7 File Descriptions

I needed to increase the maximum length of the Drupal 7 file description field that appears when you enable the File module and allow uploads in nodes. By default, the file description field restricts input to 128 characters.

The Drupal 7 File Description Field

This is set in in the File module in core Drupal:

 // Add the description field if enabled.
  if (!empty($instance['settings']['description_field']) && $item['fid']) {
    $element['description'] = array(
      '#type' => variable_get('file_description_type', 'textfield'),
      '#title' => t('Description'),
      '#value' => isset($item['description']) ? $item['description'] : '',
      '#maxlength' => variable_get('file_description_length', 128),
      '#description' => t('The description may be used as the label of the link to the file.'),

Drupal's variable_get() function looks for matching entries in your site's array of persistent variables, global $conf, that gets populated when your site loads all its modules and database. variable_get() can also be used to create a new variable and specify its value. Here the variable_get() function scans $conf for file_description_length, and if file_description_length doesn't exist, it's created and given the default value (128).

This means that file_description_length can be overridden in your site's all-powerful configuration file, settings.php:

$conf['file_description_length'] = 255;

So now when the File module processes the Description field, variable_get() will find file_description_length and return 255 as its value, ignoring the 128 supplied as the second argument to the function.

Don't Modify Core Drupal, and Look Out for Creative Users

Making changes in settings.php is better than hacking itself, because it ensures that any updates to core Drupal won't overwrite your changes.

Incidentally, the actual Description of each file is stored as field_file_description in the field_data_field_file table in the Drupal database. In MySQL it's stored as a TEXT value, which maxes out at 64 KB in size, or 65,535 single-byte characters, so a particularly dedicated user could go around your site uploading files and pasting the fascinating details of their life story into the description fields until something broke. In practice I'd limit file_description_length to a few hundred characters at most.