You are here

function theme_file_upload_help in Drupal 7

Returns HTML for help text based on file upload validators.

Parameters

$variables: An associative array containing:

  • description: The normal description for this field, specified by the user.
  • upload_validators: An array of upload validators as used in $element['#upload_validators'].

Related topics

2 theme calls to theme_file_upload_help()
file_field_widget_form in modules/file/file.field.inc
Implements hook_field_widget_form().
image_field_widget_form in modules/image/image.field.inc
Implements hook_field_widget_form().

File

modules/file/file.field.inc, line 940
Field module functionality for the File module.

Code

function theme_file_upload_help($variables) {
  $description = $variables['description'];
  $upload_validators = $variables['upload_validators'];
  $descriptions = array();
  if (strlen($description)) {
    $descriptions[] = $description;
  }
  if (isset($upload_validators['file_validate_size'])) {
    $descriptions[] = t('Files must be less than !size.', array(
      '!size' => '<strong>' . format_size($upload_validators['file_validate_size'][0]) . '</strong>',
    ));
  }
  if (isset($upload_validators['file_validate_extensions'])) {
    $descriptions[] = t('Allowed file types: !extensions.', array(
      '!extensions' => '<strong>' . check_plain($upload_validators['file_validate_extensions'][0]) . '</strong>',
    ));
  }
  if (isset($upload_validators['file_validate_image_resolution'])) {
    $max = $upload_validators['file_validate_image_resolution'][0];
    $min = $upload_validators['file_validate_image_resolution'][1];
    if ($min && $max) {
      $descriptions[] = t('Images must be at least !min pixels. Images larger than !max pixels will be resized.', array(
        '!min' => '<strong>' . $min . '</strong>',
        '!max' => '<strong>' . $max . '</strong>',
      ));
    }
    elseif ($min) {
      $descriptions[] = t('Images must be at least !min pixels.', array(
        '!min' => '<strong>' . $min . '</strong>',
      ));
    }
    elseif ($max) {
      $descriptions[] = t('Images larger than !max pixels will be resized.', array(
        '!max' => '<strong>' . $max . '</strong>',
      ));
    }
  }
  return implode('<br />', $descriptions);
}