You are here

public function ImageZoomGalleryFormatter::viewElements in Image Zoom 8.2

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides ImageZoomFormatter::viewElements

File

modules/imagezoom_gallery/src/Plugin/Field/FieldFormatter/ImageZoomGalleryFormatter.php, line 68

Class

ImageZoomGalleryFormatter
Image Zoom gallery field formatter for Image fields.

Namespace

Drupal\imagezoom_gallery\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $settings = [
    'zoomType' => $this
      ->getSetting('imagezoom_zoom_type'),
    'gallery' => 'imagezoom-thumb-wrapper',
  ];
  if ($this
    ->getSetting('imagezoom_disable')) {
    $settings['responsive'] = TRUE;
    $settings['respond'] = [
      [
        'range' => '0 - ' . $this
          ->getSetting('imagezoom_disable_width'),
        'enabled' => FALSE,
      ],
    ];
  }
  $additonal_settings = $this
    ->settingsToArray($this
    ->getSetting('imagezoom_additional'));
  $settings += $additonal_settings;
  $this->moduleHandler
    ->alter('imagezoom_settings', $settings);
  $element[] = [
    '#theme' => 'imagezoom_gallery',
    '#items' => $items,
    '#display_style' => $this
      ->getSetting('imagezoom_display_style'),
    '#zoom_style' => $this
      ->getSetting('imagezoom_zoom_style'),
    '#thumb_style' => $this
      ->getSetting('imagezoom_thumb_style'),
    '#settings' => $settings,
  ];
  $element['#attached'] = [
    'library' => [
      'imagezoom/elevatezoom',
    ],
    'drupalSettings' => [
      'imagezoom' => $settings,
    ],
  ];
  return $element;
}