You are here

ImageZoomGalleryFormatter.php in Image Zoom 8.3

File

src/Plugin/Field/FieldFormatter/ImageZoomGalleryFormatter.php
View source
<?php

namespace Drupal\imagezoom\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\imagezoom\Entity\ImageZoomOptions;

/**
 * Image Zoom gallery field formatter for Image fields.
 *
 * @FieldFormatter(
 *  id = "imagezoom_gallery",
 *  label = @Translation("Image Zoom Gallery"),
 *  field_types = {
 *     "image"
 *   }
 * )
 */
class ImageZoomGalleryFormatter extends ImageZoomFormatter {

  /**
   * {@inheritdoc}
   */
  public static function defaultSettings() {
    return [
      'imagezoom_options' => '',
    ] + parent::defaultSettings();
  }

  /**
   * {@inheritdoc}
   */

  /*public function settingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::settingsForm($form, $form_state);
    $image_styles = image_style_options(FALSE);

    $element['imagezoom_thumb_style'] = [
    '#type' => 'select',
    '#title' => $this->t('Thumbnail image style'),
    '#options' => $image_styles,
    '#empty_option' => $this->t('None (original image)'),
    '#default_value' => $this->getSetting('imagezoom_thumb_style'),
    ];

    return $element;
    }*/

  /**
   * {@inheritdoc}
   */

  /*public function settingsSummary() {
    $summary = parent::settingsSummary();
    $image_styles = image_style_options(FALSE);
    unset($image_styles['']);

    $summary[] = t('Thumbnail image style: @style', [
    '@style' => isset($image_styles[$this->getSetting('imagezoom_thumb_style')]) ?
    $image_styles[$this->getSetting('imagezoom_thumb_style')] : 'original',
    ]);

    return $summary;
    }*/

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $profile = ImageZoomOptions::load($this
      ->getSetting('imagezoom_options'));
    $options = $profile
      ->getOptions();
    $settings = [
      'zoomType' => $options['zoom_type'],
      'gallery' => 'imagezoom-thumb-wrapper',
    ];
    if ($options['disable']) {
      $settings['responsive'] = TRUE;
      $settings['respond'] = [
        [
          'range' => '0 - ' . $options['disable_width'],
          'enabled' => FALSE,
        ],
      ];
    }
    $this->moduleHandler
      ->alter('imagezoom_settings', $settings);
    $element[] = [
      '#theme' => 'imagezoom_gallery',
      '#items' => $items,
      '#display_style' => $options['display_style'],
      '#zoom_style' => $options['zoom_style'],
      '#thumb_style' => $options['thumb_style'],
      '#settings' => $settings,
    ];
    $element['#attached'] = [
      'library' => [
        'imagezoom/elevatezoom',
      ],
      'drupalSettings' => [
        'imagezoom' => $settings,
      ],
    ];
    return $element;
  }

}

Classes

Namesort descending Description
ImageZoomGalleryFormatter Image Zoom gallery field formatter for Image fields.