You are here

function elevatezoomplus_build in ElevateZoom Plus 8

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

Build the main gallery image/ stage if not using Slick asNavFor.

@todo remove first_item, first_uri (BC with older Blazy 2) at Blazy 3.x.

1 call to elevatezoomplus_build()
template_preprocess_elevatezoomplus in ./elevatezoomplus.theme.inc
Prepares variables for elevatezoomplus.html.twig templates.

File

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

Code

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'] : '';
  $item = isset($settings['_item']) ? $settings['_item'] : $item;
  $url = empty($settings['box_style']) ? file_url_transform_relative(file_create_url($uri)) : blazy()
    ->entityLoad($settings['box_style'])
    ->buildUrl($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,
  ];
  return [
    '#type' => 'inline_template',
    '#template' => '{{ stage }}',
    '#context' => [
      'stage' => blazy()
        ->getBlazy($build),
    ],
    '#attached' => blazy()
      ->attach($param + $settings),
  ];
}