1 file.theme.inc theme_file_upload_help($variables)

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

File

core/modules/file/file.theme.inc, line 272
Theme functions for the File module.

Code

function theme_file_upload_help($variables) {
  $description = (string) $variables['description'];
  $upload_validators = $variables['upload_validators'];

  $descriptions = array();

  if (strlen($description)) {
    $descriptions[] = token_replace($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];
    // Check for cases where only one dimension is specified.
    if ($min) {
      list($width, $height) = explode('x', $min);
      if (empty($height)) {
        $descriptions[] = t('Images must be at least !width pixels wide.', array('!width' => '<strong>' . $width . '</strong>'));
      }
      elseif (empty($width)) {
        $descriptions[] = t('Images must be at least !height pixels tall.', array('!height' => '<strong>' . $height . '</strong>'));
      }
      else {
        $descriptions[] = t('Images must be at least !min pixels.', array('!min' => '<strong>' . $min . '</strong>'));
      }
    }
    if ($max) {
      list($width, $height) = explode('x', $max);
      if (empty($height)) {
        $descriptions[] = t('Images wider than !width pixels will be scaled down.', array('!width' => '<strong>' . $width . '</strong>'));
      }
      elseif (empty($width)) {
        $descriptions[] = t('Images taller than !height pixels will be scaled down.', array('!height' => '<strong>' . $height . '</strong>'));
      }
      else {
        $descriptions[] = t('Images larger than !size pixels will be scaled down.', array('!size' => '<strong>' . $max . '</strong>'));
      }
    }
  }
  if (isset($upload_validators['file_validate_image_orientation'])) {
    $descriptions[] = t('If the need is indicated by EXIF data, the image will be rotated appropriately.');
  }
  return implode('<br />', $descriptions);
}