annotate modules/contrib/views_slideshow/src/Plugin/ViewsSlideshowWidget/PagerFields.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents c69a71b4f40f
children
rev   line source
Chris@5 1 <?php
Chris@5 2
Chris@5 3 namespace Drupal\views_slideshow\Plugin\ViewsSlideshowWidget;
Chris@5 4
Chris@5 5 use Drupal\Core\Form\FormStateInterface;
Chris@5 6 use Drupal\views_slideshow\ViewsSlideshowWidgetBase;
Chris@5 7
Chris@5 8 /**
Chris@5 9 * Provides a pager using fields.
Chris@5 10 *
Chris@5 11 * @ViewsSlideshowWidget(
Chris@5 12 * id = "views_slideshow_pager_fields",
Chris@5 13 * type = "views_slideshow_pager",
Chris@5 14 * label = @Translation("Fields"),
Chris@5 15 * )
Chris@5 16 */
Chris@5 17 class PagerFields extends ViewsSlideshowWidgetBase {
Chris@5 18
Chris@5 19 /**
Chris@5 20 * {@inheritdoc}
Chris@5 21 */
Chris@5 22 public function defaultConfiguration() {
Chris@5 23 return [
Chris@5 24 'views_slideshow_pager_fields_fields' => ['default' => []],
Chris@5 25 'views_slideshow_pager_fields_hover' => ['default' => 0],
Chris@5 26 ];
Chris@5 27 }
Chris@5 28
Chris@5 29 /**
Chris@5 30 * {@inheritdoc}
Chris@5 31 */
Chris@5 32 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
Chris@5 33 // Settings for fields pager.
Chris@5 34 $options = [];
Chris@5 35
Chris@5 36 // Get each field and it's name.
Chris@5 37 foreach ($this->getConfiguration()['view']->display_handler->getHandlers('field') as $field_name => $field) {
Chris@5 38 $options[$field_name] = $field->adminLabel();
Chris@5 39 }
Chris@5 40
Chris@5 41 // Need to wrap this so it indents correctly.
Chris@5 42 $form['views_slideshow_pager_fields_wrapper'] = [
Chris@5 43 '#markup' => '<div class="vs-dependent">',
Chris@5 44 ];
Chris@5 45
Chris@5 46 // Add ability to choose which fields to show in the pager.
Chris@5 47 $form['views_slideshow_pager_fields_fields'] = [
Chris@5 48 '#type' => 'checkboxes',
Chris@5 49 '#title' => $this->t('Pager fields'),
Chris@5 50 '#options' => $options,
Chris@5 51 '#default_value' => $this->getConfiguration()['views_slideshow_pager_fields_fields'],
Chris@5 52 '#description' => $this->t('Choose the fields that will appear in the pager.'),
Chris@5 53 '#states' => [
Chris@5 54 'visible' => [
Chris@5 55 ':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
Chris@5 56 ':input[name="' . $this->getConfiguration()['dependency'] . '[type]"]' => ['value' => 'views_slideshow_pager_fields'],
Chris@5 57 ],
Chris@5 58 ],
Chris@5 59 ];
Chris@5 60
Chris@5 61 // Add field to see if they would like to activate slide and pause on pager
Chris@5 62 // hover.
Chris@5 63 $form['views_slideshow_pager_fields_hover'] = [
Chris@5 64 '#type' => 'checkbox',
Chris@5 65 '#title' => $this->t('Activate Slide and Pause on Pager Hover'),
Chris@5 66 '#default_value' => $this->getConfiguration()['views_slideshow_pager_fields_hover'],
Chris@5 67 '#description' => $this->t('Should the slide be activated and paused when hovering over a pager item.'),
Chris@5 68 '#states' => [
Chris@5 69 'visible' => [
Chris@5 70 ':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
Chris@5 71 ':input[name="' . $this->getConfiguration()['dependency'] . '[type]"]' => ['value' => 'views_slideshow_pager_fields'],
Chris@5 72 ],
Chris@5 73 ],
Chris@5 74 ];
Chris@5 75
Chris@5 76 $form['views_slideshow_pager_fields_wrapper_close'] = [
Chris@5 77 '#markup' => '</div>',
Chris@5 78 ];
Chris@5 79
Chris@5 80 return $form;
Chris@5 81 }
Chris@5 82
Chris@5 83 /**
Chris@5 84 * {@inheritdoc}
Chris@5 85 */
Chris@5 86 public function checkCompatiblity($view) {
Chris@5 87 return $view->getStyle()->usesFields();
Chris@5 88 }
Chris@5 89
Chris@5 90 }