You are here

class LightgalleryManager in Lightgallery 8

Light gallery manager.

Hierarchy

Expanded class hierarchy of LightgalleryManager

3 files declare their use of LightgalleryManager
LightGallery.php in src/Plugin/views/style/LightGallery.php
LightgalleryFormatter.php in src/Plugin/Field/FieldFormatter/LightgalleryFormatter.php
lightgallery_views.theme.inc in templates/lightgallery_views.theme.inc
The module view theme.

File

src/Manager/LightgalleryManager.php, line 44

Namespace

Drupal\lightgallery\Manager
View source
class LightgalleryManager {
  protected $optionSet;

  /**
   * LightgalleryManager constructor.
   *
   * @param \Drupal\lightgallery\Optionset\LightgalleryOptionSetInterface $option_set
   *   The option set.
   */
  public function __construct(LightgalleryOptionSetInterface $option_set) {
    $this->optionSet = $option_set;
  }

  /**
   * Loads libraries to init lightgallery.
   *
   * @param int $id
   *   The id.
   *
   * @return array
   *   The array.
   */
  public function loadLibraries($id) {
    $attached = [];

    // JavaScript settings.
    $js_settings = [
      'instances' => [
        $id => $this->optionSet
          ->get(),
      ],
    ];

    // Add settings.
    $attached['drupalSettings']['lightgallery'] = $js_settings;

    // Add loader file.
    // We don't need to add the lightgallery library manually,
    // Because there is a dependency on it.
    $attached['library'][] = 'lightgallery/lightgallery.load';
    return $attached;
  }

  /**
   * Returns all fields that have to be displayed on settings form.
   */
  public static function getSettingFields() {
    return [
      // LIGHTGALLERY CORE FIELDS.
      new FieldThumbnail(),
      new FieldImage(),
      new FieldTitle(),
      new FieldThumbImageStyle(),
      new FieldLightgalleryImageStyle(),
      new FieldTitleSource(),
      new FieldMode(),
      new FieldPreload(),
      new FieldClosable(),
      new FieldLoop(),
      new FieldEscKey(),
      new FieldKeyPress(),
      new FieldControls(),
      new FieldMouseWheel(),
      new FieldDownload(),
      new FieldCounter(),
      new FieldDrag(),
      new FieldTouch(),
      // LIGHTGALLERY THUMB FIELDS.
      new FieldUseThumbs(),
      new FieldAnimateThumb(),
      new FieldCurrentPagerPosition(),
      new FieldThumbWidth(),
      new FieldThumbHeight(),
      // LIGHTGALLERY AUTPLAY FIELDS.
      new FieldAutoplay(),
      new FieldPause(),
      new FieldProgress(),
      new FieldAutoplayControls(),
      // LIGHTGALLERY FULL SCREEN FIELDS.
      new FieldFullscreen(),
      // LIGHTGALLERY PAGER FIELDS.
      new FieldPager(),
      // LIGHTGALLERY ZOOM FIELDS.
      new FieldZoom(),
      new FieldScale(),
      // LIGHTGALLERY HASH FIELDS.
      new FieldHash(),
      new FieldGalleryId(),
    ];
  }

  /**
   * Returns formatted array of all image styles.
   */
  public static function getImageStyles() {
    $options = [
      '' => t('Original image'),
    ];
    $image_styles = ImageStyle::loadMultiple();

    /** @var \Drupal\image\Entity\ImageStyle $image_style */
    foreach ($image_styles as $image_style) {
      $options[$image_style
        ->id()] = $image_style
        ->label();
    }
    return $options;
  }

  /**
   * Returns list of values that can be used as title field.
   */
  public static function getImageSourceFields() {
    return [
      '' => t('None'),
      'alt' => t('Image - Alt text'),
      'title' => t('Image - Title text'),
    ];
  }

  /**
   * Returns all available lightgallery modes.
   *
   * @return array
   *   The array.
   */
  public static function getLightgalleryModes() {
    $modes = [
      'lg-slide',
      'lg-fade',
      'lg-zoom-in',
      'lg-zoom-in-big',
      'lg-zoom-out',
      'lg-zoom-out-big',
      'lg-zoom-out-in',
      'lg-zoom-in-out',
      'lg-soft-zoom',
      'lg-scale-up',
      'lg-slide-circular',
      'lg-slide-circular-vertical',
      'lg-slide-vertical',
      'lg-slide-vertical-growth',
      'lg-slide-skew-only',
      'lg-slide-skew-only-rev',
      'lg-slide-skew-only-y',
      'lg-slide-skew-only-y-rev',
      'lg-slide-skew',
      'lg-slide-skew-rev',
      'lg-slide-skew-cross',
      'lg-slide-skew-cross-rev',
      'lg-slide-skew-ver',
      'lg-slide-skew-ver-rev',
      'lg-slide-skew-ver-cross',
      'lg-slide-skew-ver-cross-rev',
      'lg-lollipop',
      'lg-lollipop-rev',
      'lg-rotate',
      'lg-rotate-rev',
      'lg-tube',
    ];
    return array_combine($modes, $modes);
  }

  /**
   * Returns preload options.
   *
   * @return array
   *   The array.
   */
  public static function getPreloadOptions() {
    return array_combine([
      1,
      2,
      3,
      4,
    ], [
      1,
      2,
      3,
      4,
    ]);
  }

  /**
   * Returns scale options.
   *
   * @return array
   *   The array.
   */
  public static function getScaleOptions() {
    return array_combine([
      1,
      2,
      3,
      4,
    ], [
      1,
      2,
      3,
      4,
    ]);
  }

  /**
   * Returns current pager options.
   *
   * @return array
   *   The array.
   */
  public static function getCurrentPagerPositionOptions() {
    return [
      'left' => t('Left'),
      'middle' => t('Middle'),
      'right' => t('Right'),
    ];
  }

  /**
   * Flatten array and preserve keys.
   *
   * @param array $array
   *   The array.
   *
   * @return array
   *   The array.
   */
  public static function flattenArray(array $array) {
    $flattened_array = [];
    array_walk_recursive($array, function ($a, $key) use (&$flattened_array) {
      $flattened_array[$key] = $a;
    });
    return $flattened_array;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LightgalleryManager::$optionSet protected property
LightgalleryManager::flattenArray public static function Flatten array and preserve keys.
LightgalleryManager::getCurrentPagerPositionOptions public static function Returns current pager options.
LightgalleryManager::getImageSourceFields public static function Returns list of values that can be used as title field.
LightgalleryManager::getImageStyles public static function Returns formatted array of all image styles.
LightgalleryManager::getLightgalleryModes public static function Returns all available lightgallery modes.
LightgalleryManager::getPreloadOptions public static function Returns preload options.
LightgalleryManager::getScaleOptions public static function Returns scale options.
LightgalleryManager::getSettingFields public static function Returns all fields that have to be displayed on settings form.
LightgalleryManager::loadLibraries public function Loads libraries to init lightgallery.
LightgalleryManager::__construct public function LightgalleryManager constructor.