View source
<?php
namespace Drupal\lightgallery\Manager;
use Drupal\image\Entity\ImageStyle;
use Drupal\lightgallery\Field\FieldAnimateThumb;
use Drupal\lightgallery\Field\FieldAutoplay;
use Drupal\lightgallery\Field\FieldAutoplayControls;
use Drupal\lightgallery\Field\FieldClosable;
use Drupal\lightgallery\Field\FieldControls;
use Drupal\lightgallery\Field\FieldCounter;
use Drupal\lightgallery\Field\FieldCurrentPagerPosition;
use Drupal\lightgallery\Field\FieldDownload;
use Drupal\lightgallery\Field\FieldDrag;
use Drupal\lightgallery\Field\FieldEscKey;
use Drupal\lightgallery\Field\FieldFullscreen;
use Drupal\lightgallery\Field\FieldGalleryId;
use Drupal\lightgallery\Field\FieldHash;
use Drupal\lightgallery\Field\FieldImage;
use Drupal\lightgallery\Field\FieldKeyPress;
use Drupal\lightgallery\Field\FieldLightgalleryImageStyle;
use Drupal\lightgallery\Field\FieldLoop;
use Drupal\lightgallery\Field\FieldMode;
use Drupal\lightgallery\Field\FieldMouseWheel;
use Drupal\lightgallery\Field\FieldPager;
use Drupal\lightgallery\Field\FieldPause;
use Drupal\lightgallery\Field\FieldPreload;
use Drupal\lightgallery\Field\FieldProgress;
use Drupal\lightgallery\Field\FieldScale;
use Drupal\lightgallery\Field\FieldThumbHeight;
use Drupal\lightgallery\Field\FieldThumbImageStyle;
use Drupal\lightgallery\Field\FieldThumbnail;
use Drupal\lightgallery\Field\FieldThumbWidth;
use Drupal\lightgallery\Field\FieldTitle;
use Drupal\lightgallery\Field\FieldTitleSource;
use Drupal\lightgallery\Field\FieldTouch;
use Drupal\lightgallery\Field\FieldUseThumbs;
use Drupal\lightgallery\Field\FieldZoom;
use Drupal\lightgallery\Optionset\LightgalleryOptionSetInterface;
class LightgalleryManager {
protected $optionSet;
public function __construct(LightgalleryOptionSetInterface $option_set) {
$this->optionSet = $option_set;
}
public function loadLibraries($id) {
$attached = [];
$js_settings = [
'instances' => [
$id => $this->optionSet
->get(),
],
];
$attached['drupalSettings']['lightgallery'] = $js_settings;
$attached['library'][] = 'lightgallery/lightgallery.load';
return $attached;
}
public static function getSettingFields() {
return [
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(),
new FieldUseThumbs(),
new FieldAnimateThumb(),
new FieldCurrentPagerPosition(),
new FieldThumbWidth(),
new FieldThumbHeight(),
new FieldAutoplay(),
new FieldPause(),
new FieldProgress(),
new FieldAutoplayControls(),
new FieldFullscreen(),
new FieldPager(),
new FieldZoom(),
new FieldScale(),
new FieldHash(),
new FieldGalleryId(),
];
}
public static function getImageStyles() {
$options = [
'' => t('Original image'),
];
$image_styles = ImageStyle::loadMultiple();
foreach ($image_styles as $image_style) {
$options[$image_style
->id()] = $image_style
->label();
}
return $options;
}
public static function getImageSourceFields() {
return [
'' => t('None'),
'alt' => t('Image - Alt text'),
'title' => t('Image - Title text'),
];
}
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);
}
public static function getPreloadOptions() {
return array_combine([
1,
2,
3,
4,
], [
1,
2,
3,
4,
]);
}
public static function getScaleOptions() {
return array_combine([
1,
2,
3,
4,
], [
1,
2,
3,
4,
]);
}
public static function getCurrentPagerPositionOptions() {
return [
'left' => t('Left'),
'middle' => t('Middle'),
'right' => t('Right'),
];
}
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;
}
}