CCK 6.x-2.3
ImageField 6.x-3.0
Public download method

I'd like to replace the label and description for both the 'title' and 'alt' fields on the node edit page, since I'm hijacking those for a caption and photo credit. I looked at the $form array for awhile, and tried editing $form['0']['data']['alt']['#title'], etc., but this only had an impact on the fields in question when I went to edit an existing node. (Presumably because that value only refers to the 0th instance of the imagefield.)

I notice that imagefield_widget.inc seems to set alt_settings and title_settings, and that sounds more promising, but I'm unclear how to override those values.

Thank you.

Comments

quicksketch’s picture

You can override these element labels in a couple of different ways. The most common approach would be to theme the fields. Take the "theme_filefield_widget_item" function in the filefield_widget.inc file, copy it into template.php, rename it to nameofyourtheme_filefield_widget_item, then modify the labels that way. I think they're in $element['data']['title'] and $element['data']['alt'].

quicksketch’s picture

Status: Active » Closed (fixed)

Closing after lack of response.

lrickard’s picture

This worked great! I apologize for for not responding, and I'm posting back to help anyone who finds this later on.

I followed quicksketch's solution, and overrode the theme_filefield_widget_item() function:

function mythemename_filefield_widget_item($element) {
--snip--
$element['data']['alt']['#title'] = "Caption";
$element['data']['alt']['#description'] = "Whatever description you want users to see";
$element['data']['title']['#title'] = "Credit";
$element['data']['title']['#description'] = "Whatever description you want users to see";
--snip--
}

So, note to others. The $form element doesn't hold this information - it's kept in the filefield module and can be overridden.

jasonawant’s picture

Hi,

I tried the above solution, but it didn't seem to work for me. I think I'm missing something, particularly the parts that lrickard noted as '--snip--'. After a few attempts, some success with the following. Note, I only wanted to change the Title label and description.

function mytheme_filefield_widget_item($element) {
  // Put the upload button directly after the upload field.
  $element['upload']['#field_suffix'] = drupal_render($element['filefield_upload']);
  $element['upload']['#theme'] = 'filefield_widget_file';

  $element['data']['title']['#title'] = "Caption";
  $element['data']['title']['#description'] = "Text to be displayed as a caption below image.";

  $output = '';
  $output .= '<div class="filefield-element clear-block">';

  if ($element['fid']['#value'] != 0) {
    $output .= '<div class="widget-preview">';
    $output .= drupal_render($element['preview']);
    $output .= '</div>';
  }

  $output .= '<div class="widget-edit">';
  $output .=  drupal_render($element);
  $output .= '</div>';
  $output .= '</div>';

  return $output;
}
gngn’s picture

You just need to overwrite theme_imagefield_widget_item() - which just calls theme_filefield_widget_item().
This way you're changes will affect only imagefields (instead of all filefields).

function MYTHEME_imagefield_widget_item($element) {
  // add your two cents...
  // here I change the label of the description field
  // use dpm($element) to see other fields
  $element['data'] ['description']['#title'] = t('Photographer');
  
  // rest straight from theme_filefield_widget_item()
  
  // Put the upload button directly after the upload field.
  $element['upload']['#field_suffix'] = drupal_render($element['filefield_upload']);
  $element['upload']['#theme'] = 'filefield_widget_file';
  
  $output = '';
  $output .= '<div class="filefield-element clear-block">';

  if ($element['fid']['#value'] != 0) {
    $output .= '<div class="widget-preview">';
    $output .= drupal_render($element['preview']);
    $output .= '</div>';
  }

  $output .= '<div class="widget-edit">';
  $output .=  drupal_render($element);
  $output .= '</div>';
  $output .= '</div>';

  return $output;
}