You are here

public function ElevateZoomPlusManager::getOptions in ElevateZoom Plus 8

Same name and namespace in other branches
  1. 7 src/ElevateZoomPlusManager.php \Drupal\elevatezoomplus\ElevateZoomPlusManager::getOptions()

Return the options for the JSON object.

File

src/ElevateZoomPlusManager.php, line 141

Class

ElevateZoomPlusManager
Provides ElevateZoom Plus library methods mainly for hooks.

Namespace

Drupal\elevatezoomplus

Code

public function getOptions(array $settings = []) {
  $config = $this->manager
    ->configLoad();
  $fallback = empty($config['extras']['elevatezoomplus']) ? 'default' : $config['extras']['elevatezoomplus'];
  $plugin_id = isset($settings['plugin_id']) ? $settings['plugin_id'] : '';
  $filters = [
    'blazy_filter',
    'splide_filter',
    'slick_filter',
  ];
  $option_id = $plugin_id && in_array($plugin_id, $filters) ? $fallback : $settings['elevatezoomplus'];
  $optionset = ElevateZoomPlus::loadWithFallback($option_id);
  $options = $optionset
    ->getSettings(TRUE);

  // If not using Slick Carousel, provides a static grid gallery.
  if (empty($settings['nav'])) {
    $options['galleryItem'] = '[data-elevatezoomplus-trigger]';
    $options['galleryActiveClass'] = 'is-active';
    $options['gallerySelector'] = '[data-elevatezoomplus-gallery]';
  }
  if (isset($options['zoomWindowPosition']) && is_numeric($options['zoomWindowPosition'])) {
    $options['zoomWindowPosition'] = (int) $options['zoomWindowPosition'];
  }
  if (empty($options['loadingIcon'])) {
    unset($options['loadingIcon']);
  }

  // @todo remove workarounds post modules update.
  $namespace = isset($settings['namespace']) ? $settings['namespace'] : '';
  $behaviors = [];
  if ($namespace) {
    if ($namespace == 'splide') {
      $behaviors = [
        'splide',
        'splideNav',
      ];
    }
    elseif ($namespace == 'slick') {
      $behaviors = [
        'slick',
      ];
    }
  }
  if (isset($settings['media_switch']) && ($settings['media_switch'] = 'media')) {
    $behaviors[] = 'blazyMedia';
  }
  if (isset($settings['lightbox']) && ($lightbox = $settings['lightbox'])) {
    foreach ($this->manager
      ->getLightboxes() as $key) {
      if ($lightbox == $key) {
        switch ($key) {
          case 'colorbox':
            $behaviors[] = 'blazyColorbox';
            break;
          case 'photobox':
            $behaviors[] = 'blazyPhotobox';
            break;
          case 'photoswipe':
            $behaviors[] = 'blazyPhotoSwipe';
            break;
          case 'slick_lightbox':
            $behaviors[] = 'slickLightbox';
            break;
          default:
            $behaviors[] = $key;
            break;
        }
      }
    }
  }
  if ($behaviors) {
    $options['behaviors'] = $behaviors;
  }
  return $options;
}