function ImageThemeHooks::preprocessImageWidget

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/src/Hook/ImageThemeHooks.php, line 128

Class

ImageThemeHooks
Theme hook implementations for image module.

Namespace

Drupal\image\Hook

Code

public function preprocessImageWidget(array &$variables) : void {
  $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];
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.