You are here

protected function PhotoswipePreprocessProcessor::getPath in PhotoSwipe 3.x

Set image path.

1 call to PhotoswipePreprocessProcessor::getPath()
PhotoswipePreprocessProcessor::preprocess in src/PhotoswipePreprocessProcessor.php
Preprocess image.

File

src/PhotoswipePreprocessProcessor.php, line 236

Class

PhotoswipePreprocessProcessor
Preprocess photoswipe images.

Namespace

Drupal\photoswipe

Code

protected function getPath() {
  $dimensions = $this->imageDTO
    ->getDimensions();

  // Create the path to the image that will show in Photoswipe.
  if (($style_name = $this->imageDTO
    ->getSettings()['photoswipe_image_style']) && !empty($dimensions)) {

    // Load the image style.
    $style = $this->entityTypeManager
      ->getStorage('image_style')
      ->load($style_name);

    // Set the dimensions.
    $style
      ->transformDimensions($dimensions, $this->imageDTO
      ->getUri());
    $this->imageDTO
      ->setDimensions($dimensions);

    // Fetch the Image style path from the Image URI.
    return $style
      ->buildUrl($this->imageDTO
      ->getUri());
  }
  else {
    return file_create_url($this->imageDTO
      ->getUri());
  }
}