summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobin.ingelbrecht2017-05-27 19:45:40 +0200
committerrobin.ingelbrecht2017-05-27 19:45:40 +0200
commitf8981971195bd8c0a305acd32fd2fa45d3a92090 (patch)
tree6cb855d84d6fcc5c95ac4e85745733b5a39e930f
parent24671eba7c135d80332f9e639e526e42142fe4a8 (diff)
Replaced whole view config with optionset entities8.x-1.0-beta3
-rw-r--r--README.md7
-rw-r--r--config/install/slider_pro.optionset.default.yml36
-rw-r--r--config/schema/flexslider.schema.yml111
-rw-r--r--slider_pro.links.action.yml5
-rw-r--r--slider_pro.links.menu.yml7
-rw-r--r--slider_pro.permissions.yml2
-rw-r--r--slider_pro.routing.yml40
-rw-r--r--slider_pro.services.yml4
-rw-r--r--src/Controller/SliderProListBuilder.php44
-rw-r--r--src/Entity/SliderPro.php168
-rw-r--r--src/Entity/SliderProInterface.php67
-rw-r--r--src/Form/SliderProDeleteForm.php68
-rw-r--r--src/Form/SliderProForm.php528
-rw-r--r--src/Manager/SliderProManager.php44
-rw-r--r--src/Plugin/views/style/SliderPro.php574
-rw-r--r--src/SliderProDefaults.php51
-rw-r--r--src/SliderProOptionset.php90
-rw-r--r--templates/slider_pro_views.theme.inc10
18 files changed, 1284 insertions, 572 deletions
diff --git a/README.md b/README.md
index 294adc6..86e0cc7 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ This module integrates with the Views module.
## Usage
- 1. When creating a view, select the *Slider Pro* format.
- 2. Click on the *Settings* link, under the **Format** section.
- 3. Fill out the settings and apply them to your display.
+ 1. Create a new Slider Pro optionset or use the default one (admin/config/media/slider-pro)
+ 2. When creating a view, select the *Slider Pro* format.
+ 3. Click on the *Settings* link, under the **Format** section.
+ 4. Fill out the settings and apply them to your display.
diff --git a/config/install/slider_pro.optionset.default.yml b/config/install/slider_pro.optionset.default.yml
new file mode 100644
index 0000000..96ccc2c
--- /dev/null
+++ b/config/install/slider_pro.optionset.default.yml
@@ -0,0 +1,36 @@
+status: true
+dependencies: { }
+id: default
+label: Default
+options:
+ width: 100%
+ visible_size: auto
+ force_size: none
+ height: 200px
+ orientation: horizontal
+ buttons: false
+ transition: false
+ arrows: false
+ thumbnail_position: '0'
+ thumbnail_width: 100
+ thumbnail_height: 80
+ thumbnail_pointer: false
+ thumbnail_arrows: false
+ fade_thumbnail_arrows: true
+ wait_for_layers: false
+ auto_scale_layers: true
+ center_image: true
+ allow_scale_up: true
+ auto_height: false
+ slide_distance: 10
+ start_slide: 0
+ shuffle: false
+ loop: true
+ autoplay: true
+ autoplay_delay: 5000
+ autoplay_direction: normal
+ autoplay_on_hover: pause
+ keyboard: true
+ full_screen: false
+ fade_full_screen: true
+ update_hash: false
diff --git a/config/schema/flexslider.schema.yml b/config/schema/flexslider.schema.yml
new file mode 100644
index 0000000..f10e240
--- /dev/null
+++ b/config/schema/flexslider.schema.yml
@@ -0,0 +1,111 @@
+slider_pro.optionset.*:
+ type: config_entity
+ label: 'Slider Pro optionset'
+ mapping:
+ id:
+ type: string
+ label: 'ID'
+ label:
+ type: label
+ label: 'Label'
+ options:
+ type: mapping
+ label: 'Options'
+ mapping:
+ # General options
+ width:
+ type: string
+ label: 'Width'
+ height:
+ type: string
+ label: 'Height'
+ visible_size:
+ type: string
+ label: 'Visible size'
+ force_size:
+ type: string
+ label: 'Force size'
+ orientation:
+ type: string
+ label: 'Orientation'
+ buttons:
+ type: boolean
+ label: 'Buttons'
+ transition:
+ type: boolean
+ label: 'Transition'
+ arrows:
+ type: boolean
+ label: 'Arrows'
+ # Thumbnail options
+ thumbnail_position:
+ type: string
+ label: 'Position'
+ thumbnail_width:
+ type: integer
+ label: 'Width'
+ thumbnail_height:
+ type: integer
+ label: 'Height'
+ thumbnail_pointer:
+ type: boolean
+ label: 'Thumbnail pointer'
+ thumbnail_arrows:
+ type: boolean
+ label: 'Thumbnail arrows'
+ fade_thumbnail_arrows:
+ type: boolean
+ label: 'Fadet humbnail arrows'
+ # Layer options
+ wait_for_layers:
+ type: boolean
+ label: 'Wait for layers'
+ auto_scale_layers:
+ type: boolean
+ label: 'Auto scale layers'
+ # Advanced options
+ center_image:
+ type: boolean
+ label: 'Center image'
+ allow_scale_up:
+ type: boolean
+ label: 'Allow scale up'
+ start_slide:
+ type: integer
+ label: 'Start slide'
+ auto_height:
+ type: boolean
+ label: 'Auto height'
+ shuffle:
+ type: boolean
+ label: 'Shuffle'
+ loop:
+ type: boolean
+ label: 'Loop'
+ autoplay:
+ type: boolean
+ label: 'autoplay'
+ autoplay_delay:
+ type: integer
+ label: 'Autoplay delay'
+ autoplay_direction:
+ type: string
+ label: 'Autoplay direction'
+ autoplay_on_hover:
+ type: string
+ label: 'Autoplay on hover'
+ slide_distance:
+ type: integer
+ label: 'Slide distance'
+ keyboard:
+ type: boolean
+ label: 'Keyboard'
+ full_screen:
+ type: boolean
+ label: 'Full screen'
+ fade_full_screen:
+ type: boolean
+ label: 'Fade full screen'
+ update_hash:
+ type: boolean
+ label: 'Update hash' \ No newline at end of file
diff --git a/slider_pro.links.action.yml b/slider_pro.links.action.yml
new file mode 100644
index 0000000..9f0c7fd
--- /dev/null
+++ b/slider_pro.links.action.yml
@@ -0,0 +1,5 @@
+entity.slider_pro.add_form:
+ route_name: 'entity.slider_pro.add_form'
+ title: 'Add optionset'
+ appears_on:
+ - entity.slider_pro.collection
diff --git a/slider_pro.links.menu.yml b/slider_pro.links.menu.yml
new file mode 100644
index 0000000..60184c8
--- /dev/null
+++ b/slider_pro.links.menu.yml
@@ -0,0 +1,7 @@
+# Slider Pro optionset menu items definition
+entity.slider_pro.collection:
+ title: 'Slider Pro'
+ description: 'Configure optionsets.'
+ route_name: entity.slider_pro.collection
+ parent: system.admin_config_media
+ weight: 100
diff --git a/slider_pro.permissions.yml b/slider_pro.permissions.yml
new file mode 100644
index 0000000..4501e0c
--- /dev/null
+++ b/slider_pro.permissions.yml
@@ -0,0 +1,2 @@
+administer slider pro:
+ title: 'Administer the Slider Pro module'
diff --git a/slider_pro.routing.yml b/slider_pro.routing.yml
new file mode 100644
index 0000000..2956f52
--- /dev/null
+++ b/slider_pro.routing.yml
@@ -0,0 +1,40 @@
+# Slider Pro optionset routing definition
+entity.slider_pro.collection:
+ path: '/admin/config/media/slider-pro'
+ defaults:
+ _entity_list: 'slider_pro'
+ _title: 'Slider Pro'
+ requirements:
+ _permission: 'administer slider pro'
+ options:
+ _admin_route: TRUE
+
+entity.slider_pro.add_form:
+ path: '/admin/config/media/slider-pro/add'
+ defaults:
+ _entity_form: 'slider_pro.add'
+ _title: 'Add Slider Pro optionset'
+ requirements:
+ _permission: 'administer slider pro'
+ options:
+ _admin_route: TRUE
+
+entity.slider_pro.edit_form:
+ path: '/admin/config/media/slider-pro/{slider_pro}'
+ defaults:
+ _entity_form: 'slider_pro.edit'
+ _title: 'Edit Slider Pro optionset'
+ requirements:
+ _permission: 'administer slider pro'
+ options:
+ _admin_route: TRUE
+
+entity.slider_pro.delete_form:
+ path: '/admin/config/media/slider-pro/{slider_pro}/delete'
+ defaults:
+ _entity_form: 'slider_pro.delete'
+ _title: 'Delete optionset'
+ requirements:
+ _permission: 'administer slider pro'
+ options:
+ _admin_route: TRUE
diff --git a/slider_pro.services.yml b/slider_pro.services.yml
new file mode 100644
index 0000000..002d556
--- /dev/null
+++ b/slider_pro.services.yml
@@ -0,0 +1,4 @@
+services:
+ slider_pro.manager:
+ class: Drupal\slider_pro\Manager\SliderProManager
+ arguments: [] \ No newline at end of file
diff --git a/src/Controller/SliderProListBuilder.php b/src/Controller/SliderProListBuilder.php
new file mode 100644
index 0000000..3aa2e0b
--- /dev/null
+++ b/src/Controller/SliderProListBuilder.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Drupal\slider_pro\Controller;
+
+use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
+use Drupal\Core\Entity\EntityInterface;
+
+/**
+ * Class SliderProListBuilder
+ * @package Drupal\slider_pro\Controller
+ */
+class SliderProListBuilder extends ConfigEntityListBuilder {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildHeader() {
+ $header['label'] = $this->t('Name');
+ $header['id'] = $this->t('Machine name');
+ return $header + parent::buildHeader();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildRow(EntityInterface $entity) {
+ $row['label'] = $entity->label();
+ $row['id'] = $entity->id();
+ return $row + parent::buildRow($entity);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getDefaultOperations(EntityInterface $entity) {
+ $ops = parent::getDefaultOperations($entity);
+ // Do not allow deletion of the default configuration.
+ if ($entity->id() == 'default') {
+ unset($ops['delete']);
+ }
+ return $ops;
+ }
+
+}
diff --git a/src/Entity/SliderPro.php b/src/Entity/SliderPro.php
new file mode 100644
index 0000000..6e62343
--- /dev/null
+++ b/src/Entity/SliderPro.php
@@ -0,0 +1,168 @@
+<?php
+
+namespace Drupal\slider_pro\Entity;
+
+use Drupal\Core\Config\Entity\ConfigEntityBase;
+use Drupal\slider_pro\Entity\SliderProInterface;
+
+/**
+ * Defines the SliderPro entity.
+ *
+ * @ConfigEntityType(
+ * id = "slider_pro",
+ * label = @Translation("Slider pro optionset"),
+ * handlers = {
+ * "list_builder" = "Drupal\slider_pro\Controller\SliderProListBuilder",
+ * "form" = {
+ * "add" = "Drupal\slider_pro\Form\SliderProForm",
+ * "edit" = "Drupal\slider_pro\Form\SliderProForm",
+ * "delete" = "Drupal\slider_pro\Form\SliderProDeleteForm"
+ * }
+ * },
+ * config_prefix = "optionset",
+ * admin_permission = "administer slider pro",
+ * entity_keys = {
+ * "id" = "id",
+ * "label" = "label",
+ * "status" = "status"
+ * },
+ * links = {
+ * "canonical" = "/admin/config/media/slider-pro/{slider_pro}",
+ * "edit-form" = "/admin/config/media/slider-pro/{slider_pro}/edit",
+ * "delete-form" = "/admin/config/media/slider-pro/{slider_pro}/delete",
+ * "collection" = "/admin/config/media/slider-pro"
+ * },
+ * config_export = {
+ * "id",
+ * "label",
+ * "options",
+ * }
+ * )
+ */
+class SliderPro extends ConfigEntityBase implements SliderProInterface {
+ /**
+ * The Fslider pro optionset ID.
+ *
+ * @var string
+ */
+ protected $id;
+
+ /**
+ * The slider pro optionset label.
+ *
+ * @var string
+ */
+ protected $label;
+
+ /**
+ * The slider pro optionset options.
+ *
+ * @var array
+ */
+ protected $options = [];
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getOptions() {
+ return $this->options;
+
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setOptions(array $options) {
+ $this->options = $options;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getOption($name) {
+ return isset($this->options[$name]) ? $this->options[$name] : NULL;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function hasThumbnails() {
+ return !empty($this->getOption('thumbnail_position'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function hasAutoPlay() {
+ return !empty($this->getOption('autoplay'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function allowFullScreen() {
+ return !empty($this->options['advanced']['full_screen']);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function toOptionSet() {
+
+ $optionset = [
+ 'width' => $this->getOption('width'),
+ 'visibleSize' => $this->getOption('visible_size'),
+ 'forceSize' => $this->getOption('force_size'),
+ 'height' => $this->getOption('height'),
+ 'orientation' => $this->getOption('orientation'),
+ 'buttons' => $this->getOption('buttons') ? TRUE : FALSE,
+ 'fade' => $this->getOption('transition') ? TRUE : FALSE,
+ 'arrows' => $this->getOption('arrows') ? TRUE : FALSE,
+ 'centerImage' => $this->getOption('center_image') ? TRUE : FALSE,
+ 'allowScaleUp' => $this->getOption('allow_scale_up') ? TRUE : FALSE,
+ 'autoHeight' => $this->getOption('auto_height') ? TRUE : FALSE,
+ 'startSlide' => (int) $this->getOption('start_slide'),
+ 'shuffle' => $this->getOption('shuffle') ? TRUE : FALSE,
+ 'loop' => $this->getOption('loop') ? TRUE : FALSE,
+ 'autoplay' => $this->hasAutoPlay() ? TRUE : FALSE,
+ 'slideDistance' => (int) $this->getOption('slide_distance'),
+ 'keyboard' => $this->getOption('keyboard') ? TRUE : FALSE,
+ 'fullScreen' => $this->allowFullScreen() ? TRUE : FALSE,
+ 'updateHash' => $this->getOption('update_hash') ? TRUE : FALSE,
+ 'waitForLayers' => $this->getOption('wait_for_layers') ? TRUE : FALSE,
+ 'autoScaleLayers' => $this->getOption('auto_scale_layers') ? TRUE : FALSE,
+ ];
+
+
+ if ($this->hasAutoPlay()) {
+ $optionset['autoplayDelay'] = (int) $this->getOption('autoplay_delay');
+ $optionset['autoplayDirection'] = $this->getOption('autoplay_direction');
+ $optionset['autoplayOnHover'] = $this->getOption('autoplay_on_hover');
+ }
+
+ if ($this->allowFullScreen()) {
+ $optionset['fadeFullScreen'] = $this->getOption('fade_full_screen') ? TRUE : FALSE;
+ }
+
+ if ($this->hasThumbnails()) {
+ $optionset['thumbnailWidth'] = (int) $this->getOption('thumbnail_width');
+ $optionset['thumbnailHeight'] = (int) $this->getOption('thumbnail_height');
+ $optionset['thumbnailsPosition'] = $this->getOption('thumbnail_position');
+ $optionset['thumbnailPointer'] = $this->getOption('thumbnail_pointer') ? TRUE : FALSE;
+ $optionset['thumbnailArrows'] = $this->getOption('thumbnail_arrows') ? TRUE : FALSE;
+ if ($optionset['thumbnailArrows']) {
+ $optionset['fadeThumbnailArrows'] = $this->getOption('fade_thumbnail_arrows') ? TRUE : FALSE;
+ }
+ }
+
+ return $optionset;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(array $values = []) {
+ return parent::create($values);
+ }
+
+}
diff --git a/src/Entity/SliderProInterface.php b/src/Entity/SliderProInterface.php
new file mode 100644
index 0000000..7926ba6
--- /dev/null
+++ b/src/Entity/SliderProInterface.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Drupal\slider_pro\Entity;
+
+use Drupal\Core\Config\Entity\ConfigEntityInterface;
+
+/**
+ * Provides an interface for defining slider pro optionset entities.
+ */
+interface SliderProInterface extends ConfigEntityInterface {
+
+ /**
+ * Returns the array of slider pro library options.
+ *
+ * @return array
+ * The array of options.
+ */
+ public function getOptions();
+
+ /**
+ * Returns the value of a slider pro library option.
+ *
+ * @param string $name
+ * The option name.
+ *
+ * @return mixed
+ * The option value.
+ */
+ public function getOption($name);
+
+ /**
+ * Sets the slider pro library options array.
+ *
+ * @param array $options
+ * New/updated array of options.
+ */
+ public function setOptions(array $options);
+
+ /**
+ * Checks if option set requires thumbnails.
+ *
+ * @return bool
+ */
+ public function hasThumbnails();
+
+ /**
+ * Checks if option set has autoplay.
+ *
+ * @return bool
+ */
+ public function hasAutoPlay();
+
+ /**
+ * Checks if option set has full screen mode.
+ *
+ * @return bool
+ */
+ public function allowFullScreen();
+
+ /**
+ * Returns an array formatted to use as JS option set.
+ *
+ * @return array
+ */
+ public function toOptionSet();
+
+}
diff --git a/src/Form/SliderProDeleteForm.php b/src/Form/SliderProDeleteForm.php
new file mode 100644
index 0000000..4476397
--- /dev/null
+++ b/src/Form/SliderProDeleteForm.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace Drupal\slider_pro\Form;
+
+use Drupal\Core\Entity\EntityConfirmFormBase;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Url;
+
+/**
+ * Class SliderProDeleteForm
+ * @package Drupal\slider_pro\Form
+ */
+class SliderProDeleteForm extends EntityConfirmFormBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getQuestion() {
+ return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getCancelUrl() {
+ return new Url('entity.slider_pro.collection');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getConfirmText() {
+ return $this->t('Delete');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitForm(array &$form, FormStateInterface $form_state) {
+ $this->entity->delete();
+
+ drupal_set_message(
+ $this->t('Deleted the %label Slider pro optionset.',
+ [
+ '%label' => $this->entity->label(),
+ ]
+ )
+ );
+
+ $form_state->setRedirectUrl($this->getCancelUrl());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildForm(array $form, FormStateInterface $form_state) {
+ $form = parent::buildForm($form, $form_state);
+
+ if ($this->entity->id() == 'default') {
+ $form['#title'] = $this->t('The default optionset cannot be deleted.');
+ $form['description'] = ['#markup' => t('Please click Cancel to go back to the list of optionsets.')];
+ $form['actions']['submit']['#access'] = FALSE;
+ }
+
+ return $form;
+ }
+
+}
diff --git a/src/Form/SliderProForm.php b/src/Form/SliderProForm.php
new file mode 100644
index 0000000..690f149
--- /dev/null
+++ b/src/Form/SliderProForm.php
@@ -0,0 +1,528 @@
+<?php
+
+namespace Drupal\slider_pro\Form;
+
+use Drupal\Core\Entity\EntityForm;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\slider_pro\SliderProDefaults;
+
+/**
+ * Class SliderProForm
+ * @package Drupal\slider_pro\Form
+ */
+class SliderProForm extends EntityForm {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function form(array $form, FormStateInterface $form_state) {
+ $form = parent::form($form, $form_state);
+ /** @var \Drupal\slider_pro\Entity\SliderProInterface $slider_pro */
+ $slider_pro = $this->entity;
+ $options = array_merge(SliderProDefaults::defaultOptions(), $slider_pro->getOptions());
+
+ $form['label'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Label'),
+ '#maxlength' => 255,
+ '#default_value' => $slider_pro->label(),
+ '#description' => $this->t('A human-readable title for this option set.'),
+ '#required' => TRUE,
+ ];
+
+ $form['id'] = [
+ '#type' => 'machine_name',
+ '#default_value' => $slider_pro->id(),
+ '#machine_name' => [
+ 'exists' => '\Drupal\slider_pro\Entity\SliderPro::load',
+ ],
+ '#disabled' => !$slider_pro->isNew(),
+ ];
+
+ // Options Vertical Tab Group table.
+ $form['tabs'] = [
+ '#type' => 'vertical_tabs',
+ ];
+
+ // General Settings.
+ $form['general'] = [
+ '#type' => 'details',
+ '#title' => $this->t('General Settings'),
+ '#group' => 'tabs',
+ '#open' => TRUE,
+ ];
+
+ $form['general']['width'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Width'),
+ '#description' => 'The width of the slider. Eg 200px or 50%',
+ '#default_value' => $options['width'],
+ '#required' => TRUE,
+ ];
+
+ $form['general']['visible_size'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Visible size'),
+ '#description' => 'Sets the size (for example 100%) of the visible area, allowing for more slides to become visible near the selected slide. Be sure that the width of your slider is less than 100%. Example',
+ '#default_value' => $options['visible_size'],
+ '#required' => TRUE,
+ ];
+
+ $form['general']['force_size'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Force size'),
+ '#options' => [
+ 'none' => $this->t('None'),
+ 'fullWidth' => $this->t('Full width'),
+ 'fullWindow' => $this->t('Full window'),
+ ],
+ '#default_value' => $options['force_size'],
+ '#description' => $this->t('Indicates if the size of the slider will be forced to full width or full window.'),
+ '#required' => TRUE,
+ ];
+
+ $form['general']['height'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Height'),
+ '#default_value' => $options['height'],
+ '#description' => 'The height of the slider. Eg 200px or 50%',
+ ];
+
+ $form['general']['orientation'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Orientation'),
+ '#options' => [
+ 'horizontal' => $this->t('Horizontal'),
+ 'vertical' => $this->t('Vertical'),
+ ],
+ '#default_value' => $options['orientation'],
+ '#description' => $this->t('Indicates whether the slides will be arranged horizontally or vertically.'),
+ '#required' => TRUE,
+ ];
+
+ $form['general']['buttons'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Buttons'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['buttons'],
+ '#description' => $this->t('Indicates whether the buttons will be created.'),
+ '#required' => TRUE,
+ ];
+
+ $form['general']['transition'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Transition'),
+ '#options' => [
+ 0 => $this->t('Slide'),
+ 1 => $this->t('Fade'),
+ ],
+ '#default_value' => $options['transition'],
+ '#description' => $this->t('Indicates which transition will be used.'),
+ '#required' => TRUE,
+ ];
+
+ $form['general']['arrows'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Arrows'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['arrows'],
+ '#description' => $this->t('Indicates whether the arrow buttons will be created.'),
+ '#required' => TRUE,
+ ];
+
+ // Thumbnail Settings.
+ $form['thumbnails'] = [
+ '#type' => 'details',
+ '#title' => $this->t('Thumbnail Settings'),
+ '#group' => 'tabs',
+ '#open' => FALSE,
+ ];
+
+ $form['thumbnails']['thumbnail_position'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Position'),
+ '#options' => [
+ 0 => $this->t('No thumbs'),
+ 'left' => $this->t('Left'),
+ 'right' => $this->t('Right'),
+ 'top' => $this->t('Top'),
+ 'bottom' => $this->t('Bottom'),
+ ],
+ '#default_value' => $options['thumbnail_position'],
+ '#required' => TRUE,
+ '#description' => $this->t('Sets the position of the thumbnail scroller.'),
+ ];
+
+ $form['thumbnails']['thumbnail_width'] = [
+ '#type' => 'number',
+ '#title' => $this->t('Width'),
+ '#description' => $this->t('The width of each thumbnail. Eg 200px.'),
+ '#default_value' => $options['thumbnail_width'],
+ '#required' => TRUE,
+ '#states' => [
+ 'invisible' => [
+ 'select[name="thumbnail_position"]' => ['value' => '0'],
+ ],
+ ],
+ ];
+
+ $form['thumbnails']['thumbnail_height'] = [
+ '#type' => 'number',
+ '#title' => $this->t('height'),
+ '#description' => $this->t('The height of each thumbnail. Eg 200px.'),
+ '#default_value' => $options['thumbnail_height'],
+ '#required' => TRUE,
+ '#states' => [
+ 'invisible' => [
+ 'select[name="thumbnail_position"]' => ['value' => '0'],
+ ],
+ ],
+ ];
+
+ $form['thumbnails']['thumbnail_pointer'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Pointer'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['thumbnail_pointer'],
+ '#required' => TRUE,
+ '#description' => $this->t('Indicates if a pointer will be displayed for the selected thumbnail.'),
+ '#states' => [
+ 'invisible' => [
+ 'select[name="thumbnail_position"]' => ['value' => '0'],
+ ],
+ ],
+ ];
+
+ $form['thumbnails']['thumbnail_arrows'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Arrows'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['thumbnail_arrows'],
+ '#required' => TRUE,
+ '#description' => $this->t('Indicates whether the thumbnail arrows will be enabled.'),
+ '#states' => [
+ 'invisible' => [
+ 'select[name="thumbnail_position"]' => ['value' => '0'],
+ ],
+ ],
+ ];
+
+ $form['thumbnails']['fade_thumbnail_arrows'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Fade arrows'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['fade_thumbnail_arrows'],
+ '#required' => TRUE,
+ '#description' => $this->t('Indicates whether the thumbnail arrows will be faded.'),
+ '#states' => [
+ 'invisible' => [
+ [
+ 'select[name="thumbnail_position"]' => ['value' => '0'],
+ ],
+ [
+ 'select[name="thumbnail_arrows"]' => ['value' => '0'],
+ ],
+ ],
+ ],
+ ];
+
+ // Layer Settings.
+ $form['layers'] = [
+ '#type' => 'details',
+ '#title' => $this->t('Layer Settings'),
+ '#group' => 'tabs',
+ '#open' => FALSE,
+ ];
+
+ $form['layers']['wait_for_layers'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Wait for layers'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['wait_for_layers'],
+ '#description' => $this->t('Indicates whether the slider will wait for the layers to disappear before going to a new slide.'),
+ ];
+
+ $form['layers']['auto_scale_layers'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Auto scale layers'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['auto_scale_layers'],
+ '#description' => $this->t('Indicates whether the layers will be scaled automatically.'),
+ ];
+
+ // Advanced Settings.
+ $form['advanced'] = [
+ '#type' => 'details',
+ '#title' => $this->t('Advanced Settings'),
+ '#group' => 'tabs',
+ '#open' => FALSE,
+ ];
+
+ $form['advanced']['center_image'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Center image'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['center_image'],
+ '#description' => $this->t('Indicates if the image will be centered.'),
+ '#required' => TRUE,
+ ];
+
+ $form['advanced']['allow_scale_up'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Allow scale up'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['allow_scale_up'],
+ '#description' => $this->t('Indicates if the image can be scaled up more than its original size.'),
+ '#required' => TRUE,
+ ];
+
+ $form['advanced']['auto_height'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Auto height'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['auto_height'],
+ '#description' => $this->t('Indicates if height of the slider will be adjusted to the height of the selected slide.'),
+ '#required' => TRUE,
+ ];
+
+ $form['advanced']['slide_distance'] = [
+ '#type' => 'number',
+ '#title' => $this->t('Slide distance'),
+ '#default_value' => $options['slide_distance'],
+ '#description' => $this->t('Sets the distance between the slides.'),
+ '#required' => TRUE,
+ ];
+
+ $form['advanced']['start_slide'] = [
+ '#type' => 'number',
+ '#title' => $this->t('Start slide'),
+ '#default_value' => $options['start_slide'],
+ '#description' => $this->t('Sets the slide that will be selected when the slider loads.'),
+ '#required' => TRUE,
+ ];
+
+ $form['advanced']['shuffle'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Shuffle'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['shuffle'],
+ '#description' => $this->t('Indicates if the slides will be shuffled.'),
+ '#required' => TRUE,
+ ];
+
+ $form['advanced']['loop'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Loop'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['loop'],
+ '#description' => $this->t('Indicates if the slider will be loopable (infinite scrolling).'),
+ '#required' => TRUE,
+ ];
+
+ $form['advanced']['autoplay'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Autoplay'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['autoplay'],
+ '#description' => $this->t('Indicates whether or not autoplay will be enabled.'),
+ '#required' => TRUE,
+ ];
+
+ $form['advanced']['autoplay_delay'] = [
+ '#type' => 'number',
+ '#title' => $this->t('Autoplay delay'),
+ '#default_value' => $options['autoplay_delay'],
+ '#description' => $this->t('Sets the delay/interval (in milliseconds) at which the autoplay will run.'),
+ '#required' => TRUE,
+ '#states' => [
+ 'visible' => [
+ 'select[name="autoplay"]' => ['value' => '1'],
+ ],
+ ],
+ ];
+
+ $form['advanced']['autoplay_direction'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Autoplay direction'),
+ '#options' => [
+ 'normal' => $this->t('Normal'),
+ 'backwards' => $this->t('Backwards'),
+ ],
+ '#default_value' => $options['autoplay_direction'],
+ '#description' => $this->t('Indicates whether autoplay will navigate to the next slide or previous slide.'),
+ '#required' => TRUE,
+ '#states' => [
+ 'visible' => [
+ 'select[name="autoplay"]' => ['value' => '1'],
+ ],
+ ],
+ ];
+
+ $form['advanced']['autoplay_on_hover'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Autoplay on hover'),
+ '#options' => [
+ 'pause' => $this->t('Pause'),
+ 'stop' => $this->t('Stop'),
+ 'none' => $this->t('None'),
+ ],
+ '#default_value' => $options['autoplay_on_hover'],
+ '#description' => $this->t('Indicates if the autoplay will be paused or stopped when the slider is hovered.'),
+ '#required' => TRUE,
+ '#states' => [
+ 'visible' => [
+ 'select[name="autoplay"]' => ['value' => '1'],
+ ],
+ ],
+ ];
+
+ $form['advanced']['keyboard'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Keyboard'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['keyboard'],
+ '#description' => $this->t('Indicates whether keyboard navigation will be enabled.'),
+ '#required' => TRUE,
+ ];
+
+ $form['advanced']['full_screen'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Full screen'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['full_screen'],
+ '#description' => $this->t('Indicates whether the full-screen button is enabled.'),
+ '#required' => TRUE,
+ ];
+
+ $form['advanced']['fade_full_screen'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Fade full screen'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['fade_full_screen'],
+ '#description' => $this->t('Indicates whether the button will fade in only on hover.'),
+ '#required' => TRUE,
+ '#states' => [
+ 'visible' => [
+ 'select[name="full_screen"]' => ['value' => '1'],
+ ],
+ ],
+ ];
+
+ $form['advanced']['update_hash'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Update hash'),
+ '#options' => [
+ 0 => $this->t('No'),
+ 1 => $this->t('Yes'),
+ ],
+ '#default_value' => $options['update_hash'],
+ '#description' => $this->t('Indicates whether the hash will be updated when a new slide is selected.'),
+ '#required' => TRUE,
+ ];
+
+ return $form;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function save(array $form, FormStateInterface $form_state) {
+ /** @var \Drupal\slider_pro\SliderProInterface $slider_pro */
+ $slider_pro = $this->entity;
+ $status = parent::save($form, $form_state);
+
+ switch ($status) {
+ case SAVED_NEW:
+ drupal_set_message($this->t('Created the %label Slider Pro optionset.', [
+ '%label' => $slider_pro->label(),
+ ]));
+ break;
+
+ default:
+ drupal_set_message($this->t('Saved the %label Slider Pro optionset.', [
+ '%label' => $slider_pro->label(),
+ ]));
+ }
+ $form_state->setRedirectUrl($slider_pro->toUrl('collection'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
+ $options = [];
+ $values = $form_state->getValues();
+
+ foreach ($values as $key => $value) {
+ if (in_array($key, ['id', 'label'])) {
+ $entity->set($key, $value);
+ }
+ else {
+ $options[$key] = $value;
+ }
+ }
+ $entity->set('options', $options);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function actions(array $form, FormStateInterface $form_state) {
+ $actions = parent::actions($form, $form_state);
+ // Prevent access to delete button when editing default configuration.
+ if ($this->entity->id() == 'default' && isset($actions['delete'])) {
+ $actions['delete']['#access'] = FALSE;
+ }
+ return $actions;
+ }
+
+}
diff --git a/src/Manager/SliderProManager.php b/src/Manager/SliderProManager.php
new file mode 100644
index 0000000..96b0521
--- /dev/null
+++ b/src/Manager/SliderProManager.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Drupal\slider_pro\Manager;
+
+use Drupal\slider_pro\Entity\SliderPro;
+
+/**
+ * Class SliderProManager
+ * @package Drupal\slider_pro\Manager
+ */
+class SliderProManager {
+
+ /**
+ * returns array of option sets suitable for using as select list options.
+ * @return array
+ */
+ public function getOptionList() {
+ $optionsets = SliderPro::loadMultiple();
+ $options = [];
+ foreach ($optionsets as $name => $optionset) {
+ /** @var \Drupal\slider_pro\Entity\SliderProInterface $optionset */
+ $options[$name] = $optionset->label();
+ }
+
+ if (empty($options)) {
+ $options[''] = t('No defined option sets');
+ }
+ return $options;
+ }
+
+ /**
+ * Flatten array and preserve keys.
+ * @param array $array
+ * @return array
+ */
+ public static function flattenArray(array $array) {
+ $flattened_array = array();
+ array_walk_recursive($array,
+ function ($a, $key) use (&$flattened_array) {
+ $flattened_array[$key] = $a;
+ });
+ return $flattened_array;
+ }
+} \ No newline at end of file
diff --git a/src/Plugin/views/style/SliderPro.php b/src/Plugin/views/style/SliderPro.php
index 55aeafa..01770ed 100644
--- a/src/Plugin/views/style/SliderPro.php
+++ b/src/Plugin/views/style/SliderPro.php
@@ -5,8 +5,10 @@ namespace Drupal\slider_pro\Plugin\views\style;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Form\FormStateInterface;
+use Drupal\slider_pro\Manager\SliderProManager;
use Drupal\views\Plugin\views\style\StylePluginBase;
use Drupal\views\ResultRow;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @ingroup views_style_plugins
@@ -46,6 +48,28 @@ class SliderPro extends StylePluginBase {
*/
protected $usesRowClass = FALSE;
+ protected $sliderProManager;
+
+ /**
+ * SliderPro constructor.
+ */
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, SliderProManager $slider_pro_manager) {
+ parent::__construct($configuration, $plugin_id, $plugin_definition);
+ $this->sliderProManager = $slider_pro_manager;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+ return new static(
+ $configuration,
+ $plugin_id,
+ $plugin_definition,
+ $container->get('slider_pro.manager')
+ );
+ }
+
/**
* {@inheritdoc}
*/
@@ -56,6 +80,19 @@ class SliderPro extends StylePluginBase {
/**
* {@inheritdoc}
*/
+ protected function defineOptions() {
+ $options = parent::defineOptions();
+ $options['optionset'] = ['default' => 'default'];
+ $options['fields'] = [];
+ $options['thumbnail_fields'] = [];
+ $options['number_of_layers'] = 0;
+ $options['layers'] = [];
+ return $options;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
@@ -65,49 +102,6 @@ class SliderPro extends StylePluginBase {
return $form;
}
- $general_options = isset($this->options['general']) ? $this->options['general'] : [
- 'width' => '100%',
- 'visible_size' => 'auto',
- 'force_size' => 'none',
- 'height' => '200px',
- 'orientation' => 'horizontal',
- 'buttons' => 0,
- 'transition' => 0,
- 'arrows' => 0,
- 'fields' => []
- ];
- $thumb_options = isset($this->options['thumbnails']) ? $this->options['thumbnails'] : [
- 'position' => 0,
- 'fields' => array_keys($this->getAvailableFields()),
- 'width' => '100',
- 'height' => '80',
- 'thumbnail_pointer' => 0,
- 'thumbnail_arrows' => 0,
- 'fade_thumbnail_arrows' => 1,
- ];
- $layer_options = isset($this->options['layers_wrapper']) ? $this->options['layers_wrapper'] : [
- 'wait_for_layers' => 0,
- 'auto_scale_layers' => 1,
- 'number_of_layers' => 0,
- 'layers' => [],
- ];
- $advanced_options = isset($this->options['advanced']) ? $this->options['advanced'] : [
- 'center_image' => 1,
- 'allow_scale_up' => 1,
- 'auto_height' => 0,
- 'start_slide' => 0,
- 'shuffle' => 0,
- 'loop' => 1,
- 'autoplay' => 1,
- 'autoplay_delay' => 5000,
- 'autoplay_direction' => 'normal',
- 'autoplay_on_hover' => 'pause',
- 'slide_distance' => 10,
- 'keyboard' => 1,
- 'full_screen' => 0,
- 'fade_full_screen' => 1,
- 'update_hash' => 0,
- ];
$form['general'] = [
'#type' => 'details',
@@ -115,220 +109,41 @@ class SliderPro extends StylePluginBase {
'#open' => TRUE,
];
- $form['general']['width'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Width'),
- '#description' => 'The width of the slider. Eg 200px or 50%',
- '#default_value' => $general_options['width'],
- '#required' => TRUE,
- ];
-
- $form['general']['visible_size'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Visible size'),
- '#description' => 'Sets the size (for example 100%) of the visible area, allowing for more slides to become visible near the selected slide. Be sure that the width of your slider is less than 100%. Example',
- '#default_value' => $general_options['visible_size'],
- '#required' => TRUE,
- ];
-
- $form['general']['force_size'] = [
- '#type' => 'select',
- '#title' => $this->t('Force size'),
- '#options' => [
- 'none' => $this->t('None'),
- 'fullWidth' => $this->t('Full width'),
- 'fullWindow' => $this->t('Full window'),
- ],
- '#default_value' => $general_options['force_size'],
- '#description' => $this->t('Indicates if the size of the slider will be forced to full width or full window.'),
- '#required' => TRUE,
- ];
-
- $form['general']['height'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Height'),
- '#default_value' => $general_options['height'],
- '#description' => 'The height of the slider. Eg 200px or 50%',
- ];
-
- $form['general']['orientation'] = [
- '#type' => 'select',
- '#title' => $this->t('Orientation'),
- '#options' => [
- 'horizontal' => $this->t('Horizontal'),
- 'vertical' => $this->t('Vertical'),
- ],
- '#default_value' => $general_options['orientation'],
- '#description' => $this->t('Indicates whether the slides will be arranged horizontally or vertically.'),
- '#required' => TRUE,
- ];
-
- $form['general']['buttons'] = [
- '#type' => 'select',
- '#title' => $this->t('Buttons'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $general_options['buttons'],
- '#description' => $this->t('Indicates whether the buttons will be created.'),
- '#required' => TRUE,
- ];
-
- $form['general']['transition'] = [
+ $form['general']['optionset'] = [
+ '#title' => t('Option set'),
'#type' => 'select',
- '#title' => $this->t('Transition'),
- '#options' => [
- 0 => $this->t('Slide'),
- 1 => $this->t('Fade'),
- ],
- '#default_value' => $general_options['transition'],
- '#description' => $this->t('Indicates which transition will be used.'),
- '#required' => TRUE,
- ];
-
- $form['general']['arrows'] = [
- '#type' => 'select',
- '#title' => $this->t('Arrows'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $general_options['arrows'],
- '#description' => $this->t('Indicates whether the arrow buttons will be created.'),
+ '#options' => $this->sliderProManager->getOptionList(),
+ '#default_value' => $this->options['optionset'],
'#required' => TRUE,
];
$form['general']['fields'] = [
'#type' => 'checkboxes',
- '#title' => $this->t('Fields'),
+ '#title' => $this->t('Fields on slide'),
'#options' => $this->getAvailableFields(),
- '#default_value' => $general_options['fields'],
- '#description' => $this->t('Select which fields you want to display on the slider.'),
+ '#description' => $this->t('Select which fields you want to use on each slide.'),
+ '#default_value' => $this->options['fields'],
'#required' => TRUE,
];
$form['thumbnails'] = [
'#type' => 'details',
'#title' => $this->t('Thumbnail settings'),
- '#open' => ($thumb_options['position']) ? TRUE : FALSE,
- ];
-
- $form['thumbnails']['position'] = [
- '#type' => 'select',
- '#title' => $this->t('Position'),
- '#options' => [
- 0 => $this->t('No thumbs'),
- 'left' => $this->t('Left'),
- 'right' => $this->t('Right'),
- 'top' => $this->t('Top'),
- 'bottom' => $this->t('Bottom'),
- ],
- '#default_value' => $thumb_options['position'],
- '#required' => TRUE,
- '#description' => $this->t('Sets the position of the thumbnail scroller.'),
+ '#open' => FALSE,
];
- $form['thumbnails']['fields'] = [
+ $form['thumbnails']['thumbnail_fields'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Fields'),
'#options' => $this->getAvailableFields(),
- '#description' => $this->t('Select which fields you want to display on the thumbs.'),
- '#default_value' => $thumb_options['fields'],
- '#required' => TRUE,
- '#states' => [
- 'invisible' => [
- 'select[name="style_options[thumbnails][position]"]' => ['value' => '0'],
- ],
- ],
- ];
-
- $form['thumbnails']['width'] = [
- '#type' => 'number',
- '#title' => $this->t('Width'),
- '#description' => $this->t('The width of each thumbnail. Eg 200px.'),
- '#default_value' => $thumb_options['width'],
- '#required' => TRUE,
- '#states' => [
- 'invisible' => [
- 'select[name="style_options[thumbnails][position]"]' => ['value' => '0'],
- ],
- ],
- ];
-
- $form['thumbnails']['height'] = [
- '#type' => 'number',
- '#title' => $this->t('height'),
- '#description' => $this->t('The height of each thumbnail. Eg 200px.'),
- '#default_value' => $thumb_options['height'],
- '#required' => TRUE,
- '#states' => [
- 'invisible' => [
- 'select[name="style_options[thumbnails][position]"]' => ['value' => '0'],
- ],
- ],
- ];
-
- $form['thumbnails']['thumbnail_pointer'] = [
- '#type' => 'select',
- '#title' => $this->t('Pointer'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $thumb_options['thumbnail_pointer'],
- '#required' => TRUE,
- '#description' => $this->t('Indicates if a pointer will be displayed for the selected thumbnail.'),
- '#states' => [
- 'invisible' => [
- 'select[name="style_options[thumbnails][position]"]' => ['value' => '0'],
- ],
- ],
- ];
-
- $form['thumbnails']['thumbnail_arrows'] = [
- '#type' => 'select',
- '#title' => $this->t('Arrows'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $thumb_options['thumbnail_arrows'],
- '#required' => TRUE,
- '#description' => $this->t('Indicates whether the thumbnail arrows will be enabled.'),
- '#states' => [
- 'invisible' => [
- 'select[name="style_options[thumbnails][position]"]' => ['value' => '0'],
- ],
- ],
- ];
-
- $form['thumbnails']['fade_thumbnail_arrows'] = [
- '#type' => 'select',
- '#title' => $this->t('Fade arrows'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $thumb_options['fade_thumbnail_arrows'],
- '#required' => TRUE,
- '#description' => $this->t('Indicates whether the thumbnail arrows will be faded.'),
- '#states' => [
- 'invisible' => [
- [
- 'select[name="style_options[thumbnails][position]"]' => ['value' => '0'],
- ],
- [
- 'select[name="style_options[thumbnails][thumbnail_arrows]"]' => ['value' => '0'],
- ],
- ],
- ],
+ '#description' => $this->t('Select which fields you want to display on the thumbs. This setting will only be applied if the selected optionset defines a thumbnail position'),
+ '#default_value' => $this->options['thumbnail_fields'],
];
$form['layers_wrapper'] = [
'#type' => 'details',
'#title' => $this->t('Layer settings'),
- '#open' => !empty($layer_options['number_of_layers']) ? TRUE : FALSE,
+ '#open' => !empty($this->options['number_of_layers']) ? TRUE : FALSE,
];
$form['layers_wrapper']['number_of_layers'] = [
@@ -338,32 +153,10 @@ class SliderPro extends StylePluginBase {
[0, 1, 2, 3, 4, 5],
[$this->t('None'), 1, 2, 3, 4, 5]
),
- '#default_value' => $layer_options['number_of_layers'],
+ '#default_value' => $this->options['number_of_layers'],
'#description' => $this->t('Provide the number of layers you want to use. Afterwards save the options and re-open them to start configuring your layers.'),
];
- $form['layers_wrapper']['wait_for_layers'] = [
- '#type' => 'select',
- '#title' => $this->t('Wait for layers'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $layer_options['wait_for_layers'],
- '#description' => $this->t('Indicates whether the slider will wait for the layers to disappear before going to a new slide.'),
- ];
-
- $form['layers_wrapper']['auto_scale_layers'] = [
- '#type' => 'select',
- '#title' => $this->t('Auto scale layers'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $layer_options['auto_scale_layers'],
- '#description' => $this->t('Indicates whether the layers will be scaled automatically.'),
- ];
-
$form['layers_wrapper']['layers'] = [
'#type' => 'table',
'#header' => [
@@ -389,15 +182,15 @@ class SliderPro extends StylePluginBase {
'#empty' => $this->t('No layers configured yet...'),
];
- for ($key = 0; $key < $layer_options['number_of_layers']; $key++) {
- $layer = isset($layer_options['layers'][$key]) ? $layer_options['layers'][$key] : [
+ for ($key = 0; $key < $this->options['number_of_layers']; $key++) {
+ $layer = isset($this->options['layers'][$key]) ? $this->options['layers'][$key] : [
'fields' => [],
- 'background' => NULL,
- 'position' => NULL,
- 'show_transition' => NULL,
- 'hide_transition' => NULL,
- 'show_delay' => NULL,
- 'stay_duration' => NULL,
+ 'background' => '',
+ 'position' => 'topLeft',
+ 'show_transition' => 'left',
+ 'hide_transition' => 'right',
+ 'show_delay' => 0,
+ 'stay_duration' => 0,
'weight' => 0,
];
@@ -423,7 +216,6 @@ class SliderPro extends StylePluginBase {
'sp-black' => $this->t('Black transparant'),
],
'#default_value' => $layer['background'],
- '#required' => TRUE,
];
$form['layers_wrapper']['layers'][$key]['position'] = [
@@ -539,200 +331,46 @@ class SliderPro extends StylePluginBase {
'#limit_validation_errors' => [],
];*/
- $form['advanced'] = [
- '#type' => 'details',
- '#title' => $this->t('Advanced settings'),
- '#open' => FALSE,
- ];
-
- $form['advanced']['center_image'] = [
- '#type' => 'select',
- '#title' => $this->t('Center image'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $advanced_options['center_image'],
- '#description' => $this->t('Indicates if the image will be centered.'),
- '#required' => TRUE,
- ];
-
- $form['advanced']['allow_scale_up'] = [
- '#type' => 'select',
- '#title' => $this->t('Allow scale up'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $advanced_options['allow_scale_up'],
- '#description' => $this->t('Indicates if the image can be scaled up more than its original size.'),
- '#required' => TRUE,
- ];
-
- $form['advanced']['auto_height'] = [
- '#type' => 'select',
- '#title' => $this->t('Auto height'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $advanced_options['auto_height'],
- '#description' => $this->t('Indicates if height of the slider will be adjusted to the height of the selected slide.'),
- '#required' => TRUE,
- ];
-
- $form['advanced']['slide_distance'] = [
- '#type' => 'number',
- '#title' => $this->t('Slide distance'),
- '#default_value' => $advanced_options['slide_distance'],
- '#description' => $this->t('Sets the distance between the slides.'),
- '#required' => TRUE,
- ];
-
- $form['advanced']['start_slide'] = [
- '#type' => 'number',
- '#title' => $this->t('Start slide'),
- '#default_value' => $advanced_options['start_slide'],
- '#description' => $this->t('Sets the slide that will be selected when the slider loads.'),
- '#required' => TRUE,
- ];
-
- $form['advanced']['shuffle'] = [
- '#type' => 'select',
- '#title' => $this->t('Shuffle'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $advanced_options['shuffle'],
- '#description' => $this->t('Indicates if the slides will be shuffled.'),
- '#required' => TRUE,
- ];
-
- $form['advanced']['loop'] = [
- '#type' => 'select',
- '#title' => $this->t('Loop'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $advanced_options['loop'],
- '#description' => $this->t('Indicates if the slider will be loopable (infinite scrolling).'),
- '#required' => TRUE,
- ];
-
- $form['advanced']['autoplay'] = [
- '#type' => 'select',
- '#title' => $this->t('Autoplay'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $advanced_options['autoplay'],
- '#description' => $this->t('Indicates whether or not autoplay will be enabled.'),
- '#required' => TRUE,
- ];
-
- $form['advanced']['autoplay_delay'] = [
- '#type' => 'number',
- '#title' => $this->t('Autoplay delay'),
- '#default_value' => $advanced_options['autoplay_delay'],
- '#description' => $this->t('Sets the delay/interval (in milliseconds) at which the autoplay will run.'),
- '#required' => TRUE,
- '#states' => [
- 'visible' => [
- 'select[name="style_options[advanced][autoplay]"]' => ['value' => '1'],
- ],
- ],
- ];
-
- $form['advanced']['autoplay_direction'] = [
- '#type' => 'select',
- '#title' => $this->t('Autoplay direction'),
- '#options' => [
- 'normal' => $this->t('Normal'),
- 'backwards' => $this->t('Backwards'),
- ],
- '#default_value' => $advanced_options['autoplay_direction'],
- '#description' => $this->t('Indicates whether autoplay will navigate to the next slide or previous slide.'),
- '#required' => TRUE,
- '#states' => [
- 'visible' => [
- 'select[name="style_options[advanced][autoplay]"]' => ['value' => '1'],
- ],
- ],
- ];
-
- $form['advanced']['autoplay_on_hover'] = [
- '#type' => 'select',
- '#title' => $this->t('Autoplay on hover'),
- '#options' => [
- 'pause' => $this->t('Pause'),
- 'stop' => $this->t('Stop'),
- 'none' => $this->t('None'),
- ],
- '#default_value' => $advanced_options['autoplay_on_hover'],
- '#description' => $this->t('Indicates if the autoplay will be paused or stopped when the slider is hovered.'),
- '#required' => TRUE,
- '#states' => [
- 'visible' => [
- 'select[name="style_options[advanced][autoplay]"]' => ['value' => '1'],
- ],
- ],
- ];
-
- $form['advanced']['keyboard'] = [
- '#type' => 'select',
- '#title' => $this->t('Keyboard'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $advanced_options['keyboard'],
- '#description' => $this->t('Indicates whether keyboard navigation will be enabled.'),
- '#required' => TRUE,
- ];
-
- $form['advanced']['full_screen'] = [
- '#type' => 'select',
- '#title' => $this->t('Full screen'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $advanced_options['full_screen'],
- '#description' => $this->t('Indicates whether the full-screen button is enabled.'),
- '#required' => TRUE,
- ];
-
- $form['advanced']['fade_full_screen'] = [
- '#type' => 'select',
- '#title' => $this->t('Fade full screen'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $advanced_options['fade_full_screen'],
- '#description' => $this->t('Indicates whether the button will fade in only on hover.'),
- '#required' => TRUE,
- '#states' => [
- 'visible' => [
- 'select[name="style_options[advanced][full_screen]"]' => ['value' => '1'],
- ],
- ],
- ];
+ }
- $form['advanced']['update_hash'] = [
- '#type' => 'select',
- '#title' => $this->t('Update hash'),
- '#options' => [
- 0 => $this->t('No'),
- 1 => $this->t('Yes'),
- ],
- '#default_value' => $advanced_options['update_hash'],
- '#description' => $this->t('Indicates whether the hash will be updated when a new slide is selected.'),
- '#required' => TRUE,
- ];
+ /**
+ * {@inheritdoc}
+ */
+ public function validateOptionsForm(&$form, FormStateInterface $form_state) {
+ parent::validateOptionsForm($form, $form_state);
+ $style_options = $form_state->getValue('style_options');
+
+ // Flatten style options array.
+ $nested_options = [
+ 'layers' => !empty($style_options['layers_wrapper']['layers']) ? $style_options['layers_wrapper']['layers'] : [],
+ 'fields' => $style_options['general']['fields'],
+ 'thumbnail_fields' => $style_options['thumbnails']['thumbnail_fields'],
+ ];
+ unset($style_options['layers_wrapper']['layers']);
+ unset($style_options['general']['fields']);
+ unset($style_options['thumbnails']['thumbnail_fields']);
+
+ $form_state->setValue(array(
+ 'style_options'
+ ), array_merge($nested_options, SliderProManager::flattenArray($style_options)));
+
+ // Unset nested values.
+ $form_state->unsetValue(array('style_options', 'general'));
+ $form_state->unsetValue(array('style_options', 'thumbnails'));
+ $form_state->unsetValue(array('style_options', 'layers_wrapper'));
+
+ // Validation.
+ $optionset = \Drupal\slider_pro\Entity\SliderPro::load($form_state->getValue([
+ 'style_options',
+ 'optionset'
+ ]));
+ $thumbnail_fields = $form_state->getValue([
+ 'style_options',
+ 'thumbnail_fields'
+ ]);
+ if ($optionset->hasThumbnails() && empty(array_filter($thumbnail_fields))) {
+ $form_state->setErrorByName('thumbnails][thumbnail_fields][title', $this->t('The "Thumbnails fields" field is required as the optionset has a position for thumbnails configured.'));
+ }
}
/**
@@ -742,32 +380,20 @@ class SliderPro extends StylePluginBase {
$rows = [];
$fields = array_keys($this->getAvailableFields());
- if (empty($this->options['general'])) {
- // Settings have not been set yet.
- return $rows;
- }
-
- $general_options = $this->options['general'];
- $thumb_options = $this->options['thumbnails'];
- $layer_options = $this->options['layers_wrapper'];
for ($i = 0; $i < count($this->view->result); $i++) {
$rows[$i]['layers'] = [];
for ($j = 0; $j < count($fields); $j++) {
$field = $fields[$j];
$rendered_field = $this->view->style_plugin->getField($i, $field);
- if (in_array($field, array_filter($general_options['fields']))) {
+ if (in_array($field, array_filter($this->options['fields']))) {
$rows[$i]['slide'][$fields[$j]] = $rendered_field;
}
- if (in_array($field, array_filter($thumb_options['fields']))) {
+ if (in_array($field, array_filter($this->options['thumbnail_fields']))) {
$rows[$i]['thumb'][$fields[$j]] = $rendered_field;
}
- if (!$layer_options['layers']) {
- // Make sure layers is an array.
- $layer_options['layers'] = [];
- }
- $layers = array_slice($layer_options['layers'], 0, $layer_options['number_of_layers']);
+ $layers = array_slice($this->options['layers'], 0, $this->options['number_of_layers']);
foreach ($layers as $key => $layer) {
if (!isset($rows[$i]['layers'][$key])) {
$rows[$i]['layers'][$key] = $layer;
diff --git a/src/SliderProDefaults.php b/src/SliderProDefaults.php
new file mode 100644
index 0000000..2f5e24b
--- /dev/null
+++ b/src/SliderProDefaults.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Drupal\slider_pro;
+
+/**
+ * Class SliderProDefaults
+ * @package Drupal\slider_pro
+ */
+class SliderProDefaults {
+
+ /**
+ * Returns default slider pro library options.
+ * @return array
+ */
+ public static function defaultOptions() {
+ return [
+ 'width' => '100%',
+ 'visible_size' => 'auto',
+ 'force_size' => 'none',
+ 'height' => '200px',
+ 'orientation' => 'horizontal',
+ 'buttons' => 0,
+ 'transition' => 0,
+ 'arrows' => 0,
+ 'thumbnail_position' => 0,
+ 'thumbnail_width' => '100',
+ 'thumbnail_height' => '80',
+ 'thumbnail_pointer' => 0,
+ 'thumbnail_arrows' => 0,
+ 'fade_thumbnail_arrows' => 1,
+ 'wait_for_layers' => 0,
+ 'auto_scale_layers' => 1,
+ 'center_image' => 1,
+ 'allow_scale_up' => 1,
+ 'auto_height' => 0,
+ 'start_slide' => 0,
+ 'shuffle' => 0,
+ 'loop' => 1,
+ 'autoplay' => 1,
+ 'autoplay_delay' => 5000,
+ 'autoplay_direction' => 'normal',
+ 'autoplay_on_hover' => 'pause',
+ 'slide_distance' => 10,
+ 'keyboard' => 1,
+ 'full_screen' => 0,
+ 'fade_full_screen' => 1,
+ 'update_hash' => 0,
+ ];
+ }
+
+}
diff --git a/src/SliderProOptionset.php b/src/SliderProOptionset.php
deleted file mode 100644
index 1eb7aab..0000000
--- a/src/SliderProOptionset.php
+++ /dev/null
@@ -1,90 +0,0 @@
-<?php
-
-namespace Drupal\slider_pro;
-
-/**
- * Class SliderProOptionset
- * @package Drupal\slider_pro
- */
-class SliderProOptionset {
-
- protected $useThumbs;
- protected $hasLayers;
- protected $allowFullScreen;
- protected $hasAutoPlay;
- protected $options;
-
- /**
- * SliderProOptionset constructor.
- * @param $options
- */
- public function __construct($options) {
- $this->options = $options;
- $this->useThumbs = !empty($options['thumbnails']['position']);
- $this->hasLayers = !empty($options['layers_wrapper']['layers']);
- $this->allowFullScreen = !empty($this->options['advanced']['full_screen']);
- $this->hasAutoPlay = !empty($this->options['advanced']['autoplay']);
- }
-
- /**
- * Returns optionset.
- * @return array|bool
- */
- public function toArray() {
-
- if (!isset($this->options['general'])) {
- return FALSE;
- }
-
- $optionset = [
- 'width' => $this->options['general']['width'],
- 'visibleSize' => $this->options['general']['visible_size'],
- 'forceSize' => $this->options['general']['force_size'],
- 'height' => $this->options['general']['height'],
- 'orientation' => $this->options['general']['orientation'],
- 'buttons' => ($this->options['general']['buttons']) ? TRUE : FALSE,
- 'fade' => ($this->options['general']['transition']) ? TRUE : FALSE,
- 'arrows' => ($this->options['general']['arrows']) ? TRUE : FALSE,
- 'centerImage' => ($this->options['advanced']['center_image']) ? TRUE : FALSE,
- 'allowScaleUp' => ($this->options['advanced']['allow_scale_up']) ? TRUE : FALSE,
- 'autoHeight' => ($this->options['advanced']['auto_height']) ? TRUE : FALSE,
- 'startSlide' => (int) $this->options['advanced']['start_slide'],
- 'shuffle' => ($this->options['advanced']['shuffle']) ? TRUE : FALSE,
- 'loop' => ($this->options['advanced']['loop']) ? TRUE : FALSE,
- 'autoplay' => ($this->options['advanced']['autoplay']) ? TRUE : FALSE,
- 'slideDistance' => (int) $this->options['advanced']['autoplay'],
- 'keyboard' => ($this->options['advanced']['keyboard']) ? TRUE : FALSE,
- 'fullScreen' => ($this->options['advanced']['full_screen']) ? TRUE : FALSE,
- 'updateHash' => ($this->options['advanced']['update_hash']) ? TRUE : FALSE,
- ];
-
- if ($this->hasAutoPlay) {
- $optionset['autoplayDelay'] = (int) $this->options['advanced']['autoplay_delay'];
- $optionset['autoplayDirection'] = $this->options['advanced']['autoplay_direction'];
- $optionset['autoplayOnHover'] = $this->options['advanced']['autoplay_on_hover'];
- }
-
- if ($this->allowFullScreen) {
- $optionset['fadeFullScreen'] = ($this->options['advanced']['fade_full_screen']) ? TRUE : FALSE;
- }
-
- if ($this->useThumbs) {
- $optionset['thumbnailWidth'] = (int) $this->options['thumbnails']['width'];
- $optionset['thumbnailHeight'] = (int) $this->options['thumbnails']['height'];
- $optionset['thumbnailsPosition'] = $this->options['thumbnails']['position'];
- $optionset['thumbnailPointer'] = ($this->options['thumbnails']['thumbnail_pointer']) ? TRUE : FALSE;
- $optionset['thumbnailArrows'] = ($this->options['thumbnails']['thumbnail_arrows']) ? TRUE : FALSE;
- if ($optionset['thumbnailArrows']) {
- $optionset['fadeThumbnailArrows'] = ($this->options['thumbnails']['fade_thumbnail_arrows']) ? TRUE : FALSE;
- }
- }
-
- if ($this->hasLayers) {
- $optionset['waitForLayers'] = ($this->options['layers_wrapper']['wait_for_layers']) ? TRUE : FALSE;
- $optionset['autoScaleLayers'] = ($this->options['layers_wrapper']['auto_scale_layers']) ? TRUE : FALSE;
- }
-
- return $optionset;
- }
-
-} \ No newline at end of file
diff --git a/templates/slider_pro_views.theme.inc b/templates/slider_pro_views.theme.inc
index 3a33c71..0c2ba67 100644
--- a/templates/slider_pro_views.theme.inc
+++ b/templates/slider_pro_views.theme.inc
@@ -1,6 +1,6 @@
<?php
-use Drupal\slider_pro\SliderProOptionset;
+use Drupal\slider_pro\Entity\SliderPro;
/**
* Prepares variables for slider pro view templates.
@@ -12,8 +12,8 @@ function template_preprocess_slider_pro_views_style(array &$variables) {
return;
}
- if (!$optionset = new SliderProOptionset($variables['options'])) {
- // Settings have not been set yet.
+ if (!$optionset = SliderPro::load($variables['options']['optionset'])) {
+ // For some reason, no options set could be loaded.
return;
}
@@ -22,7 +22,7 @@ function template_preprocess_slider_pro_views_style(array &$variables) {
$content = array(
'#theme' => 'slider_pro',
'#rows' => $variables['rows'],
- '#uses_thumbnails' => !empty($variables['options']['thumbnails']['position']),
+ '#uses_thumbnails' => $optionset->hasThumbnails(),
'#id' => $id,
);
@@ -31,7 +31,7 @@ function template_preprocess_slider_pro_views_style(array &$variables) {
// JavaScript settings
$js_settings = array(
'instances' => array(
- $id => $optionset->toArray(),
+ $id => $optionset->toOptionSet(),
),
);
// Add JS.