elevatezoomplus.theme.inc in ElevateZoom Plus 7
Same filename and directory in other branches
Hooks and preprocess functions for the Blazy module.
File
elevatezoomplus.theme.incView source
<?php
/**
* @file
* Hooks and preprocess functions for the Blazy module.
*/
use Drupal\blazy\Blazy;
/**
* Returns HTML for a elevatezoomplus.
*
* @param array $variables
* An associative array containing:
* - element: The original theme elements.
* - settings: HTML related settings.
* - stage: The static main preview image if not using Slick with asNavFor.
*
* @ingroup themeable
*/
function theme_elevatezoomplus(array $variables) {
extract($variables);
// Only provides static stage if not using Slick asNavFor.
$stage = empty($stage) ? '' : drupal_render($stage);
// Appends and wraps the already-rendered #children.
return '<div' . drupal_attributes($attributes_array) . '>' . $stage . $content . '</div>';
}
/**
* Prepares variables for theme_elevatezoomplus().
*/
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'] : [];
}
/**
* Build the main gallery image/ stage, if not using Slick asNavFor.
*
* @todo remove first_item for _item post blazy:2.x.
*/
function elevatezoomplus_build(array $settings = []) {
$uri = isset($settings['_uri']) ? $settings['_uri'] : (isset($settings['first_uri']) ? $settings['first_uri'] : '');
$item = isset($settings['first_item']) ? $settings['first_item'] : new \stdClass();
$item = isset($settings['_item']) ? $settings['_item'] : $item;
$url = empty($settings['box_style']) ? file_create_url($uri) : image_style_url($settings['box_style'], $uri);
$style = empty($settings['thumbnail_style']) ? '' : $settings['thumbnail_style'];
$param = [
'image_style' => $style,
'lazy' => 'blazy',
'uri' => $uri,
];
$id = Blazy::getHtmlId('elevatezoomplus');
$zoom = [
'data-zoom-image' => $url,
];
$attrs = [
'class' => [
'elevatezoomplus elevatezoomplus--stage',
],
'id' => $id,
] + $zoom;
$build = [
'item' => $item,
'settings' => $param,
'item_attributes' => $attrs,
];
$stage = blazy()
->getBlazy($build);
$stage['#attached'] = blazy()
->attach($param + $settings);
$attrs = [
'class' => [
'elevatezoomplus-stage blazy',
],
'data-blazy' => '',
];
return Blazy::container($stage, $attrs);
}
Functions
Name | Description |
---|---|
elevatezoomplus_build | Build the main gallery image/ stage, if not using Slick asNavFor. |
template_preprocess_elevatezoomplus | Prepares variables for theme_elevatezoomplus(). |
theme_elevatezoomplus | Returns HTML for a elevatezoomplus. |