You are here

public function ImageDTO::__construct in PhotoSwipe 3.x

Construct new ImageDTO object.

Parameters

array $variables: Variables from which fetch the image information.

File

src/ImageDTO.php, line 99

Class

ImageDTO
Contains image item.

Namespace

Drupal\photoswipe

Code

public function __construct(array $variables) {
  $this->settings = $variables['display_settings'];

  // In case if entity is instance of Media use referenced field provided
  // specified by user.
  $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'];
}