You are here

function template_preprocess_image_widget in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/image/image.field.inc \template_preprocess_image_widget()

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 19
Implement an image field, based on the file module's file field.

Code

function template_preprocess_image_widget(&$variables) {
  $element = $variables['element'];
  $variables['attributes'] = [
    'class' => [
      'image-widget',
      'js-form-managed-file',
      'form-managed-file',
      'clearfix',
    ],
  ];
  $variables['data'] = [];
  foreach (Element::children($element) as $child) {
    $variables['data'][$child] = $element[$child];
  }
}