function theme_file_upload_help

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

4 theme calls to theme_file_upload_help()
FileWidget::formElement in drupal/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php
Implements \Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
FileWidget::formMultipleElements in drupal/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php
Overrides \Drupal\field\Plugin\Type\Widget\WidgetBase::formMultipleElements().
ImageWidget::formMultipleElements in drupal/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php
Overrides \Drupal\file\Plugin\field\widget\FileWidget::formMultipleElements().
locale_translate_import_form in drupal/core/modules/locale/locale.bulk.inc
Form constructor for the translation import screen.

File

drupal/core/modules/file/file.field.inc, line 783
Field module functionality for the File module.

Code

function theme_file_upload_help($variables) {
  $description = $variables['description'];
  $upload_validators = $variables['upload_validators'];
  $cardinality = $variables['cardinality'];
  $descriptions = array();
  if (strlen($description)) {
    $descriptions[] = _filter_htmlcorrector($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($cardinality)) {
    if ($cardinality == -1) {
      $descriptions[] = t('Unlimited number of files can be uploaded to this field.');
    }
    else {
      $descriptions[] = format_plural($cardinality, 'This field can store only one file.', 'This field can store at most @count files.');
    }
  }
  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 && $min == $max) {
      $descriptions[] = t('Images must be exactly !size pixels.', array(
        '!size' => '<strong>' . $max . '</strong>',
      ));
    }
    elseif ($min && $max) {
      $descriptions[] = t('Images must be between !min and !max pixels.', array(
        '!min' => '<strong>' . $min . '</strong>',
        '!max' => '<strong>' . $max . '</strong>',
      ));
    }
    elseif ($min) {
      $descriptions[] = t('Images must be larger than !min pixels.', array(
        '!min' => '<strong>' . $min . '</strong>',
      ));
    }
    elseif ($max) {
      $descriptions[] = t('Images must be smaller than !max pixels.', array(
        '!max' => '<strong>' . $max . '</strong>',
      ));
    }
  }
  return implode('<br />', $descriptions);
}