You are here

function template_preprocess_elevatezoomplus in ElevateZoom Plus 8

Same name and namespace in other branches
  1. 7 elevatezoomplus.theme.inc \template_preprocess_elevatezoomplus()

Prepares variables for elevatezoomplus.html.twig templates.

See also

Drupal\commerce_product\ProductVariationFieldRenderer

File

./elevatezoomplus.theme.inc, line 16
Hooks and preprocess functions for the Blazy module.

Code

function template_preprocess_elevatezoomplus(array &$variables) {
  $element = $variables['element'];
  foreach ([
    'attributes',
    'content',
    'settings',
  ] as $key) {
    $variables[$key] = isset($element['#' . $key]) ? $element['#' . $key] : [];
  }
  $attributes =& $variables['attributes'];
  $settings = $variables['settings'];
  $json = elevatezoomplus()
    ->getOptions($settings);

  // Remove problematic container class which cause multiple AJAX classes due
  // to using the same attributes array affecting this theme.
  $class = isset($settings['ajax_replace_class']) ? $settings['ajax_replace_class'] : '';
  if ($class && isset($attributes['class'])) {
    $attributes['class'] = array_diff((array) $attributes['class'], [
      $class,
    ]);
  }
  $attributes['data-elevatezoomplus'] = Json::encode($json);
  $variables['content_attributes'] = [
    'data-blazy' => '',
  ];

  // Checks if Splide/ Slick asNavFor, or regular carousels, Blazy Grid, etc.
  // Only provides static stage if not using Splide/Slick asNavFor.
  $variables['stage'] = empty($settings['nav']) ? elevatezoomplus_build($settings) : [];
}