You are here

public function ElevateZoomPlusManager::preprocessBlazy in ElevateZoom Plus 8

Same name and namespace in other branches
  1. 7 src/ElevateZoomPlusManager.php \Drupal\elevatezoomplus\ElevateZoomPlusManager::preprocessBlazy()

Overrides variables for theme_blazy().

File

src/ElevateZoomPlusManager.php, line 289

Class

ElevateZoomPlusManager
Provides ElevateZoom Plus library methods mainly for hooks.

Namespace

Drupal\elevatezoomplus

Code

public function preprocessBlazy(&$variables) {
  $settings = $variables['settings'];
  $zoom_url = $variables['url'];

  // Support video thumbnail since `url` points to a provider site.
  if ($settings['type'] == 'video' && !empty($settings['box_url'])) {
    $zoom_url = $settings['box_url'];
  }

  // Re-use thumbnail style for the stage/ preview image.
  $stage_url = empty($variables['attributes']['data-thumb']) ? $zoom_url : $variables['attributes']['data-thumb'];

  // Provides the expected attributes for JS.
  $variables['url_attributes']['data-image'] = $stage_url;
  $variables['url_attributes']['data-zoom-image'] = $zoom_url;

  // If using Slick asNavFor, make the litebox link as a zoom trigger as well.
  $id = Blazy::getHtmlId('elevatezoomplus');
  if (!empty($settings['nav'])) {
    $variables['url_attributes']['class'][] = 'elevatezoomplus';
    $variables['url_attributes']['id'] = $id;
  }
  else {
    $variables['item_attributes']['id'] = $id;
  }
}