You are here

public function PhotoswipePreprocessProcessor::preprocess in PhotoSwipe 3.x

Preprocess image.

Parameters

array $variables: Variables.

File

src/PhotoswipePreprocessProcessor.php, line 120

Class

PhotoswipePreprocessProcessor
Preprocess photoswipe images.

Namespace

Drupal\photoswipe

Code

public function preprocess(array &$variables) {
  $this->imageDTO = ImageDTO::createFromVariables($variables);
  $image = $this
    ->getRandarableImage($variables);
  $this
    ->setDimensions($image);
  $variables['image'] = $image;
  $variables['path'] = $this
    ->getPath();
  $variables['attributes']['class'][] = 'photoswipe';
  $variables['attributes']['data-size'] = $this->imageDTO
    ->getWidth() . 'x' . $this->imageDTO
    ->getHeight();
  $variables['attributes']['data-overlay-title'] = $this
    ->getCaption();
  if (isset($image['#style_name']) && $image['#style_name'] === 'hide') {

    // Do not display if hidden is selected:
    $variables['attributes']['class'][] = 'hidden';
  }
}