You are here

function template_preprocess_elevatezoomplus in ElevateZoom Plus 7

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

Prepares variables for theme_elevatezoomplus().

File

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

Code

function template_preprocess_elevatezoomplus(array &$variables) {

  // Supported themes: Blazy (field|item_list), slick_wrapper, gridstack.
  $element = $variables['element'];
  $variables['settings'] = [];
  foreach ([
    'blazy',
    'build',
    'context',
    'settings',
  ] as $key) {
    if (isset($element['#' . $key])) {
      $settings = isset($element['#' . $key]['settings']) ? $element['#' . $key]['settings'] : [];
      $variables['settings'] = $key == 'build' || $key == 'context' ? $settings : $element['#' . $key];
      break;
    }
  }

  // Reset theme attributes as we are a wrapper/ container here.
  $settings = $variables['settings'];
  $json = elevatezoomplus()
    ->getOptions($settings);
  $variables['attributes_array'] = isset($element['#container_attributes']) ? $element['#container_attributes'] : [];
  $variables['attributes_array']['data-elevatezoomplus'] = drupal_json_encode($json);
  $variables['attributes_array']['class'][] = 'elevatezoomplus-wrapper';

  // Checks if we have Slick asNavFor, or regular Slick, Blazy Grid, etc.
  // Only provides static stage if not using Slick asNavFor.
  $variables['stage'] = empty($settings['nav']) ? elevatezoomplus_build($settings) : [];
  $variables['content'] = isset($element['#children']) ? $element['#children'] : [];
}