You are here

function template_preprocess_image_anchor in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/image/image.admin.inc \template_preprocess_image_anchor()
  2. 9 core/modules/image/image.admin.inc \template_preprocess_image_anchor()

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/image.admin.inc, line 113
Administration pages for image settings.

Code

function template_preprocess_image_anchor(&$variables) {
  $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',
      ],
    ],
  ];
}