This can a useful shortcut to theming when a bunch of nodes contain links that should contain the same caption text.

For example, imagine document nodes each containing a title, a brief description and filefield link to a .pdf. When displayed as a list, the document links should read "download PDF". Currently, the user would be required to reset the description for every node, which is tedious and not evident to novice users.

I've tried implementing this by adding the following to filefield_widget_settings():

$form['default_description'] = array (
  '#type' => 'textfield',
  '#title' => t('Default description'),
  '#default_value' => $widget['default_description'] ? $widget['default_description'] : '',
  '#size' => 64,
  '#description' => t('Text used for all outgoing links to this field\'s content.  Leave blank to use the name of the uploaded file.'),
);

and modifying _filefield_file_form() accordingly:

if (strlen($file['description'])) { $description = $file['description']; }
else { 
  $description = (strlen($field['widget']['default_description'])) 
    ? $field['widget']['default_description'] 
    : $file['filename'];
}

$form['description'] = array(
  '#type' => 'textfield', 
  '#default_value' => $description, 
  '#maxlength' => 256, 
);

but it doesn't seem as if the 'default_description' is carrying over to the $field array in the latter.

What step am I missing?

Comments

jpetso’s picture

Status: Active » Closed (won't fix)

From what I remember, you'd need to add 'default_description' to the list of to-be-saved form elements at the bottom of filefield_widget_settings(), and maybe clear the cache after that.

However, I don't think it's a good idea to have something like this in the upstream version of filefield. If something is a question of theming, it shouldn't be done by changing the description, especially not if "Download PDF" is not actually the description of the file but an instruction for the user. I believe that it's wrong to mix that up, and I also think that you will save yourself hours of patching filefield (once for each time you update) by doing one theming function once and right.

Like, for example, you could check if the description equals the file name - which is the default value for the description - and in that case, output something with "Download PDF" in it.

Currently, I don't think there's a good enough use case to name all files in a field (which, by assumption, are mostly different ones) the same. Therefore, I'm marking this issue as "won't fix". Hope it helps a bit nevertheless.

drowlflood’s picture

Understood; this could easily be seen as breaking one of the tenets of MVC separation.

Nonetheless, thanks for pointing me in the right direction. Changing the 'save' case of filefield_widget_settings() to include 'default_description' was all that was needed, and it's working like a charm!