You are here

function template_preprocess_imagezoom_thumb in Image Zoom 8.3

Same name and namespace in other branches
  1. 8.2 modules/imagezoom_gallery/imagezoom_gallery.module \template_preprocess_imagezoom_thumb()
  2. 7.2 modules/imagezoom_gallery/imagezoom_gallery.module \template_preprocess_imagezoom_thumb()

Preprocess function for imagezoom_thumb.

File

./imagezoom.module, line 115
Provides an Image Zoom field formatter for Image fields.

Code

function template_preprocess_imagezoom_thumb(&$variables) {
  $item = $variables['item'];
  if ($variables['display_style']) {
    $image_style = ImageStyle::load($variables['display_style']);
    $variables['image'] = $image_style
      ->buildUrl($item->entity
      ->getFileUri());
  }
  else {
    $variables['image'] = file_create_url($item->entity
      ->getFileUri());
  }
  if ($variables['zoom_style']) {
    $image_style = ImageStyle::load($variables['zoom_style']);
    $variables['zoom'] = $image_style
      ->buildUrl($item->entity
      ->getFileUri());
  }
  else {
    $variables['zoom'] = file_create_url($item->entity
      ->getFileUri());
  }

  /** @var Drupal\Core\Image\Image $image */
  if ($variables['thumb_style']) {
    $image_style = ImageStyle::load($variables['thumb_style']);
    $variables['thumb'] = $image_style
      ->buildUrl($item->entity
      ->getFileUri());
    $image = \Drupal::service('image.factory')
      ->get($image_style
      ->buildUri($item->entity
      ->getFileUri()));
  }
  else {
    $variables['thumb'] = file_create_url($item->entity
      ->getFileUri());
    $image = \Drupal::service('image.factory')
      ->get($item->entity
      ->getFileUri());
  }
  $variables['width'] = $image
    ->getWidth();
  $variables['height'] = $image
    ->getHeight();
}