Loading src/ImageDTO.php +4 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,10 @@ class ImageDTO { $this->uri = $this->item->entity->getFileUri(); $this->entity = $variables['entity']; $this->setDimensions([ ImageDTO::HEIGHT => $item->height, ImageDTO::WIDTH => $item->width, ]); } /** Loading src/PhotoswipePreprocessProcessor.php +2 −32 Original line number Diff line number Diff line Loading @@ -23,13 +23,6 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { */ protected $entityTypeManager; /** * Image factory. * * @var \Drupal\Core\Image\ImageFactory */ protected $imageFactory; /** * Token. * Loading Loading @@ -70,8 +63,6 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * Entity manager. * @param \Drupal\Core\Image\ImageFactory $imageFactory * Image factory. * @param \Drupal\Core\Utility\Token $token * Token. * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager Loading @@ -83,14 +74,12 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { */ public function __construct( EntityTypeManagerInterface $entityTypeManager, ImageFactory $imageFactory, Token $token, LanguageManagerInterface $languageManager, LoggerChannelFactoryInterface $channelFactory, RendererInterface $renderer ) { $this->entityTypeManager = $entityTypeManager; $this->imageFactory = $imageFactory; $this->token = $token; $this->languageManager = $languageManager; $this->renderer = $renderer; Loading @@ -103,7 +92,6 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { public static function create(ContainerInterface $container) { return new static( $container->get('entity_type.manager'), $container->get('image.factory'), $container->get('token'), $container->get('language_manager'), $container->get('logger.factory'), Loading @@ -120,7 +108,6 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { public function preprocess(array &$variables) { $this->imageDTO = ImageDTO::createFromVariables($variables); $image = $this->getRandarableImage($variables); $this->setDimensions($image); $variables['image'] = $image; $variables['path'] = $this->getPath(); Loading Loading @@ -214,6 +201,8 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { '#uri' => $this->imageDTO->getUri(), '#alt' => $this->imageDTO->getAlt(), '#title' => $this->imageDTO->getTitle(), '#width' => $this->imageDTO->getWidth(), '#height' => $this->imageDTO->getHeight(), '#attributes' => $this->imageDTO->getItem()->_attributes, '#style_name' => $this->imageDTO->getSettings()['photoswipe_node_style'], ]; Loading Loading @@ -252,23 +241,4 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { } } /** * Set image dimensions. * * @param array $image * Randarable array of image. */ protected function setDimensions(array &$image) { // The image.factory service will check if our image is valid. $image_file = $this->imageFactory->get($this->imageDTO->getUri()); if ($image_file->isValid()) { $image['#width'] = $image_file->getWidth(); $image['#height'] = $image_file->getHeight(); $this->imageDTO->setDimensions([ ImageDTO::HEIGHT => $image_file->getHeight(), ImageDTO::WIDTH => $image_file->getWidth(), ]); } } } Loading
src/ImageDTO.php +4 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,10 @@ class ImageDTO { $this->uri = $this->item->entity->getFileUri(); $this->entity = $variables['entity']; $this->setDimensions([ ImageDTO::HEIGHT => $item->height, ImageDTO::WIDTH => $item->width, ]); } /** Loading
src/PhotoswipePreprocessProcessor.php +2 −32 Original line number Diff line number Diff line Loading @@ -23,13 +23,6 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { */ protected $entityTypeManager; /** * Image factory. * * @var \Drupal\Core\Image\ImageFactory */ protected $imageFactory; /** * Token. * Loading Loading @@ -70,8 +63,6 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * Entity manager. * @param \Drupal\Core\Image\ImageFactory $imageFactory * Image factory. * @param \Drupal\Core\Utility\Token $token * Token. * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager Loading @@ -83,14 +74,12 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { */ public function __construct( EntityTypeManagerInterface $entityTypeManager, ImageFactory $imageFactory, Token $token, LanguageManagerInterface $languageManager, LoggerChannelFactoryInterface $channelFactory, RendererInterface $renderer ) { $this->entityTypeManager = $entityTypeManager; $this->imageFactory = $imageFactory; $this->token = $token; $this->languageManager = $languageManager; $this->renderer = $renderer; Loading @@ -103,7 +92,6 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { public static function create(ContainerInterface $container) { return new static( $container->get('entity_type.manager'), $container->get('image.factory'), $container->get('token'), $container->get('language_manager'), $container->get('logger.factory'), Loading @@ -120,7 +108,6 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { public function preprocess(array &$variables) { $this->imageDTO = ImageDTO::createFromVariables($variables); $image = $this->getRandarableImage($variables); $this->setDimensions($image); $variables['image'] = $image; $variables['path'] = $this->getPath(); Loading Loading @@ -214,6 +201,8 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { '#uri' => $this->imageDTO->getUri(), '#alt' => $this->imageDTO->getAlt(), '#title' => $this->imageDTO->getTitle(), '#width' => $this->imageDTO->getWidth(), '#height' => $this->imageDTO->getHeight(), '#attributes' => $this->imageDTO->getItem()->_attributes, '#style_name' => $this->imageDTO->getSettings()['photoswipe_node_style'], ]; Loading Loading @@ -252,23 +241,4 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface { } } /** * Set image dimensions. * * @param array $image * Randarable array of image. */ protected function setDimensions(array &$image) { // The image.factory service will check if our image is valid. $image_file = $this->imageFactory->get($this->imageDTO->getUri()); if ($image_file->isValid()) { $image['#width'] = $image_file->getWidth(); $image['#height'] = $image_file->getHeight(); $this->imageDTO->setDimensions([ ImageDTO::HEIGHT => $image_file->getHeight(), ImageDTO::WIDTH => $image_file->getWidth(), ]); } } }