You are here

class PhotoswipeResponsivePreprocessProcessor in PhotoSwipe 3.x

Preprocess photoswipe images.

Hierarchy

Expanded class hierarchy of PhotoswipeResponsivePreprocessProcessor

1 file declares its use of PhotoswipeResponsivePreprocessProcessor
photoswipe.theme.inc in ./photoswipe.theme.inc
Photoswipe theme preprocess functions.

File

src/PhotoswipeResponsivePreprocessProcessor.php, line 11

Namespace

Drupal\photoswipe
View source
class PhotoswipeResponsivePreprocessProcessor extends PhotoswipePreprocessProcessor {

  /**
   * {@inheritDoc}
   */
  protected function getRandarableImage($variables) {
    $item = $this->imageDTO
      ->getItem();
    $settings = $this->imageDTO
      ->getSettings();
    $image_style_store = $this->entityTypeManager
      ->getStorage('image_style');
    $resp_image_store = $this->entityTypeManager
      ->getStorage('responsive_image_style');
    $responsive_image_style = $resp_image_store
      ->load($this->imageDTO
      ->getSettings()['photoswipe_node_style']);
    $cache_tags = [];
    $image_styles_to_load = [];
    if ($responsive_image_style) {
      $cache_tags = Cache::mergeTags($cache_tags, $responsive_image_style
        ->getCacheTags());
      $image_styles_to_load = $responsive_image_style
        ->getImageStyleIds();
    }
    $image_styles = $image_style_store
      ->loadMultiple($image_styles_to_load);
    foreach ($image_styles as $image_style) {
      $cache_tags = Cache::mergeTags($cache_tags, $image_style
        ->getCacheTags());
    }
    $image = [
      '#theme' => 'responsive_image_formatter',
      '#item' => $item,
      '#item_attributes' => $item->_attributes,
      '#responsive_image_style_id' => $responsive_image_style ? $responsive_image_style
        ->id() : '',
      '#cache' => [
        'tags' => $cache_tags,
      ],
    ];
    $meta_a = CacheableMetadata::createFromRenderArray($image);
    $meta_b = CacheableMetadata::createFromObject($item
      ->getEntity());
    $meta_a
      ->merge($meta_b)
      ->applyTo($image);
    if (isset($variables['delta']) && $variables['delta'] === 0 && !empty($settings['photoswipe_node_style_first'])) {
      $responsive_image_style_first = $resp_image_store
        ->load($settings['photoswipe_node_style_first']);
      $image['#responsive_image_style_id'] = $responsive_image_style_first
        ->id();
    }
    return $image;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhotoswipePreprocessProcessor::$entityTypeManager protected property Entity type manager.
PhotoswipePreprocessProcessor::$imageDTO protected property Image DTO.
PhotoswipePreprocessProcessor::$imageFactory protected property Image factory.
PhotoswipePreprocessProcessor::$languageManager protected property Language manager.
PhotoswipePreprocessProcessor::$logger protected property Logger.
PhotoswipePreprocessProcessor::$renderer protected property Renderer.
PhotoswipePreprocessProcessor::$token protected property Token.
PhotoswipePreprocessProcessor::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
PhotoswipePreprocessProcessor::getCaption protected function Set the caption.
PhotoswipePreprocessProcessor::getPath protected function Set image path.
PhotoswipePreprocessProcessor::preprocess public function Preprocess image.
PhotoswipePreprocessProcessor::setDimensions protected function Set image dimensions.
PhotoswipePreprocessProcessor::__construct public function Constructs new PhotoswipePreprocessProcessor object.
PhotoswipeResponsivePreprocessProcessor::getRandarableImage protected function Build randarable array for given image. Overrides PhotoswipePreprocessProcessor::getRandarableImage