function ImageThemeHooks::preprocessImageAnchor

Prepares variables for image anchor templates.

Default template: image-anchor.html.twig.

Parameters

array $variables: An associative array containing:

  • element: An associative array containing the image.

File

core/modules/image/src/Hook/ImageThemeHooks.php, line 295

Class

ImageThemeHooks
Theme hook implementations for image module.

Namespace

Drupal\image\Hook

Code

public function preprocessImageAnchor(array &$variables) : void {
  $element = $variables['element'];
  $rows = [];
  $row = [];
  foreach (Element::children($element) as $n => $key) {
    $element[$key]['#attributes']['title'] = $element[$key]['#title'];
    unset($element[$key]['#title']);
    $row[] = [
      'data' => $element[$key],
    ];
    if ($n % 3 == 3 - 1) {
      $rows[] = $row;
      $row = [];
    }
  }
  $variables['table'] = [
    '#type' => 'table',
    '#header' => [],
    '#rows' => $rows,
    '#attributes' => [
      'class' => [
        'image-anchor',
      ],
    ],
  ];
}

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