ImageDTO.php in PhotoSwipe 3.x
File
src/ImageDTO.php
View source
<?php
namespace Drupal\photoswipe;
use Drupal\Core\Language\Language;
use Drupal\media\MediaInterface;
use Drupal\media_entity\MediaInterface as MediaEntityInterface;
class ImageDTO {
const HEIGHT = 'height';
const WIDTH = 'width';
protected $settings;
protected $item;
protected $variables;
protected $uri;
protected $title;
protected $alt;
protected $entity;
protected $caption;
protected $dimensions = [
self::HEIGHT => 150,
self::WIDTH => 150,
];
protected $path;
public function __construct(array $variables) {
$this->settings = $variables['display_settings'];
$this->item = ($item = $variables['item']) && ($item->entity instanceof MediaInterface || $item->entity instanceof MediaEntityInterface) && $item->entity
->hasField($this->settings['photoswipe_reference_image_field']) ? $item->entity
->get($this->settings['photoswipe_reference_image_field']) : $item;
!empty($item->alt) ? $this->alt = $item->alt : !empty($item->field_file_image_alt_text[Language::LANGCODE_NOT_SPECIFIED]) && ($this->alt = $item->field_file_image_alt_text[Language::LANGCODE_NOT_SPECIFIED][0]['value']);
!empty($item->title) ? $this->item = $item->title : !empty($item->field_file_image_title_text[Language::LANGCODE_NOT_SPECIFIED]) && ($this->item = $item->field_file_image_title_text[Language::LANGCODE_NOT_SPECIFIED][0]['value']);
$this->uri = $this->item->entity
->getFileUri();
$this->entity = $variables['entity'];
}
public static function createFromVariables(array $variables) {
return new static($variables);
}
public function getSettings() {
return $this->settings;
}
public function getItem() {
return $this->item;
}
public function getEntity() {
return $this->entity;
}
public function getAlt() {
return $this->alt;
}
public function getUri() {
return $this->uri;
}
public function getCaption() {
return $this->caption;
}
public function getTitle() {
return $this->title;
}
public function getDimensions() {
return $this->dimensions;
}
public function setDimensions(array $dimensions) {
$this->dimensions = $dimensions;
}
public function getWidth() {
return $this->dimensions[self::WIDTH];
}
public function getHeight() {
return $this->dimensions[self::HEIGHT];
}
public function getPath() {
return $this->path;
}
}