0

How can I change or replace the text: "Images must be larger than 200x200" in the image field for a specific content type?

I have created a image field CCK and I have put the Minimum resolution for Images of 200x200. When I put this restriction appears the text: Images must be larger than 200x200. I need to replace or change this text by: Minimum size for images: 200x200, in some content types. Is it possible?

I am working with Drupal 6.x.

Thanks.

2 Answers 2

2

According my test you can use two ways:

1) rewrite theme_filefield_widget_file() function inside your template.php of your theme, to replace the $element['#description'] value, for example:

function phptemplate_filefield_widget_file($element) {
  $output = '';

  switch ($element['#name']) {
    case 'NAME_FIELD'://name of field in $element['#name']
        $element['#description'] = 'Images must be larger than 200x200';
        break;
    }


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

  if (isset($element['#field_prefix'])) {
    $output .= $element['#field_prefix'];
  }

  _form_set_class($element, array('form-file'));
  $output .= '<input type="file" name="'. $element['#name'] .'"'. ($element['#attributes'] ? ' '. drupal_attributes($element['#attributes']) : '') .' id="'. $element['#id'] .'" size="'. $element['#size'] ."\" />\n";

  if (isset($element['#field_suffix'])) {
    $output .= $element['#field_suffix'];
  }

  $output .= '</div>';

  return theme('form_element', $element, $output);
} 

(I found very useful to change all file/image fields, but in the example the switch/case allows select an specific field that can be of your content type)

2) form_alter hook in a custom module (in this example module name is change_form_values_form_alter), and attach a function to $form['#after_build'] array:

function change_form_values_form_alter($form, &$form_state) {

    if ($form['form_id']['#id'] == 'YOUR_FORM_ID') {
        $form['#after_build'][] = 'change_form_values_file_widget';
    }

}

function change_form_values_file_widget($form, &$form_state) {
    $form['GROUP_NAME_IF_EXIST']['FILE_FIELD_NAME'][0]['upload']['#description'] = 'Images must be larger than 200x200';
    return $form;
}

Also, seems that all help string, including other validations like max size, extensions allowed, are overwritten, so I guess that you should add the string including other texts.

I hope information be useful.

2

you can use string overrides module or a hook_form_alter and override the text with

$form['PHOTO_FIELD_NAME']['#description'] = 'Images must be larger than 200x200';
1
  • 1
    It's a good idea, but I tested and the code didn't work for me. It works: $form['PHOTO_FIELD_NAME'][0]['upload']['#description']= 'Images must be larger than 200x200';
    – cabita
    Nov 1, 2011 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.