function template_preprocess_image_widget

template_preprocess_image_widget(&$variables)

Prepares variables for image widget templates.

Default template: image-widget.html.twig.

Parameters

array $variables: An associative array containing:

  • element: A render element representing the image field widget.

File

core/modules/image/image.field.inc, line 20
Implement an image field, based on the file module's file field.

Code

function template_preprocess_image_widget(&$variables) {
  $element = $variables['element'];

  $variables['attributes'] = array('class' => array('image-widget', 'js-form-managed-file', 'form-managed-file', 'clearfix'));

  if (!empty($element['fids']['#value'])) {
    $file = reset($element['#files']);
    $element['file_' . $file->id()]['filename']['#suffix'] = ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> ';
  }

  $variables['data'] = array();
  foreach (Element::children($element) as $child) {
    $variables['data'][$child] = $element[$child];
  }

}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!image!image.field.inc/function/template_preprocess_image_widget/8.1.x