diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index 3305a00..f42a15c 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -722,7 +722,15 @@ function theme_file_widget_multiple($variables) { * * @ingroup themeable */ -function theme_file_upload_help($variables) { +function file_upload_help($variables = array()) { + // Merge in defaults. + $variables += array( + 'description' => '', + 'upload_validators' => array(), + 'cardinality' => NULL, + 'separator' => '
', + ); + $description = $variables['description']; $upload_validators = $variables['upload_validators']; $cardinality = $variables['cardinality']; @@ -730,40 +738,43 @@ function theme_file_upload_help($variables) { $descriptions = array(); if (strlen($description)) { - $descriptions[] = _filter_htmlcorrector($description); + $descriptions['description'] = _filter_htmlcorrector($description); } if (isset($upload_validators['file_validate_size'])) { - $descriptions[] = t('Files must be less than !size.', array('!size' => '' . format_size($upload_validators['file_validate_size'][0]) . '')); + $descriptions['file_validate_size'] = t('Files must be less than !size.', array('!size' => '' . format_size($upload_validators['file_validate_size'][0]) . '')); } if (isset($upload_validators['file_validate_extensions'])) { - $descriptions[] = t('Allowed file types: !extensions.', array('!extensions' => '' . check_plain($upload_validators['file_validate_extensions'][0]) . '')); + $descriptions['file_validate_extensions'] = t('Allowed file types: !extensions.', array('!extensions' => '' . check_plain($upload_validators['file_validate_extensions'][0]) . '')); } if (isset($cardinality)) { if ($cardinality == -1) { - $descriptions[] = t('Unlimited number of files can be uploaded to this field.'); + $descriptions['cardinality'] = 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.'); + $descriptions['cardinality'] = 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' => '' . $max . '')); + $descriptions['file_validate_image_resolution'] = t('Images must be exactly !size pixels.', array('!size' => '' . $max . '')); } elseif ($min && $max) { - $descriptions[] = t('Images must be between !min and !max pixels.', array('!min' => '' . $min . '', '!max' => '' . $max . '')); + $descriptions['file_validate_image_resolution'] = t('Images must be between !min and !max pixels.', array('!min' => '' . $min . '', '!max' => '' . $max . '')); } elseif ($min) { - $descriptions[] = t('Images must be larger than !min pixels.', array('!min' => '' . $min . '')); + $descriptions['file_validate_image_resolution'] = t('Images must be larger than !min pixels.', array('!min' => '' . $min . '')); } elseif ($max) { - $descriptions[] = t('Images must be smaller than !max pixels.', array('!max' => '' . $max . '')); + $descriptions['file_validate_image_resolution'] = t('Images must be smaller than !max pixels.', array('!max' => '' . $max . '')); } } - return implode('
', $descriptions); + // Allow other modules to modify the + Drupal::moduleHandler()->alter(__FUNCTION__, $descriptions, $variables); + + return implode($variables['separator'], $descriptions); } /** diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 0d66adb..1e5de89 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -596,9 +596,6 @@ function file_theme() { 'file_formatter_table' => array( 'variables' => array('items' => NULL), ), - 'file_upload_help' => array( - 'variables' => array('description' => NULL, 'upload_validators' => NULL, 'cardinality' => NULL), - ), ); } diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php index 63564fa..1cbca0e 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php @@ -164,7 +164,7 @@ protected function formMultipleElements(EntityInterface $entity, array $items, $ // field. These are added here so that they may be referenced easily // through a hook_form_alter(). $elements['#file_upload_title'] = t('Add a new file'); - $elements['#file_upload_description'] = theme('file_upload_help', array('description' => '', 'upload_validators' => $elements[0]['#upload_validators'], 'cardinality' => $cardinality)); + $elements['#file_upload_description'] = file_upload_help(array('description' => '', 'upload_validators' => $elements[0]['#upload_validators'], 'cardinality' => $cardinality)); } return $elements; @@ -225,7 +225,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr $default_fids = $element['#extended'] ? $element['#default_value']['fids'] : $element['#default_value']; if (empty($default_fids)) { - $element['#description'] = theme('file_upload_help', array('description' => $element['#description'], 'upload_validators' => $element['#upload_validators'], 'cardinality' => $cardinality)); + $element['#description'] = file_upload_help(array('description' => $element['#description'], 'upload_validators' => $element['#upload_validators'], 'cardinality' => $cardinality)); $element['#multiple'] = $cardinality != 1 ? TRUE : FALSE; if ($cardinality != 1 && $cardinality != -1) { $element['#element_validate'] = array('file_field_widget_multiple_count_validate'); diff --git a/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php b/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php index d0ae8fa..9f3af40 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php +++ b/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php @@ -87,11 +87,11 @@ protected function formMultipleElements(EntityInterface $entity, array $items, $ if ($cardinality == 1) { // If there's only one field, return it as delta 0. if (empty($elements[0]['#default_value']['fids'])) { - $elements[0]['#description'] = theme('file_upload_help', array('description' => $this->fieldDefinition->getFieldDescription(), 'upload_validators' => $elements[0]['#upload_validators'], 'cardinality' => $cardinality)); + $elements[0]['#description'] = file_upload_help(array('description' => $this->fieldDefinition->getFieldDescription(), 'upload_validators' => $elements[0]['#upload_validators'], 'cardinality' => $cardinality)); } } else { - $elements['#file_upload_description'] = theme('file_upload_help', array('upload_validators' => $elements[0]['#upload_validators'], 'cardinality' => $cardinality)); + $elements['#file_upload_description'] = file_upload_help(array('upload_validators' => $elements[0]['#upload_validators'], 'cardinality' => $cardinality)); } return $elements; diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 8a15656..fe8ab8b 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -54,7 +54,7 @@ function locale_translate_import_form($form, &$form_state) { $form['file'] = array( '#type' => 'file', '#title' => t('Translation file'), - '#description' => theme('file_upload_help', array('description' => t('A Gettext Portable Object file.'), 'upload_validators' => $validators)), + '#description' => file_upload_help(array('description' => t('A Gettext Portable Object file.'), 'upload_validators' => $validators)), '#size' => 50, '#upload_validators' => $validators, '#attributes' => array('class' => array('file-import-input')),