More tidying.
[yaffs-website] / web / modules / contrib / views_bootstrap / src / Plugin / views / style / ViewsBootstrapCarousel.php
1 <?php
2
3 namespace Drupal\views_bootstrap\Plugin\views\style;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\style\StylePluginBase;
7
8 /**
9  * Style plugin to render each item as a row in a Bootstrap Carousel.
10  *
11  * @ingroup views_style_plugins
12  *
13  * @ViewsStyle(
14  *   id = "views_bootstrap_carousel",
15  *   title = @Translation("Bootstrap Carousel"),
16  *   help = @Translation("Displays rows in a Bootstrap Carousel."),
17  *   theme = "views_bootstrap_carousel",
18  *   theme_file = "../views_bootstrap.theme.inc",
19  *   display_types = {"normal"}
20  * )
21  */
22 class ViewsBootstrapCarousel extends StylePluginBase {
23   /**
24    * Does the style plugin for itself support to add fields to it's output.
25    *
26    * @var bool
27    */
28   protected $usesFields = TRUE;
29
30   /**
31    * Definition.
32    */
33   protected function defineOptions() {
34     $options = parent::defineOptions();
35
36     $options['interval'] = ['default' => 5000];
37     $options['navigation'] = ['default' => TRUE];
38     $options['indicators'] = ['default' => TRUE];
39     $options['pause'] = ['default' => TRUE];
40     $options['wrap'] = ['default' => TRUE];
41
42     $options['image'] = ['default' => ''];
43     $options['title'] = ['default' => ''];
44     $options['description'] = ['default' => ''];
45
46     return $options;
47   }
48
49   /**
50    * Render the given style.
51    */
52   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
53     parent::buildOptionsForm($form, $form_state);
54
55     $fields = ['' => t('<None>')];
56     $fields += $this->displayHandler->getFieldLabels(TRUE);
57
58     $form['interval'] = [
59       '#type' => 'number',
60       '#title' => $this->t('Interval'),
61       '#description' => t('The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.'),
62       '#default_value' => $this->options['interval'],
63     ];
64
65     $form['navigation'] = [
66       '#type' => 'checkbox',
67       '#title' => $this->t('Show navigation'),
68       '#default_value' => $this->options['navigation'],
69     ];
70
71     $form['indicators'] = [
72       '#type' => 'checkbox',
73       '#title' => $this->t('Show indicators'),
74       '#default_value' => $this->options['indicators'],
75     ];
76
77     $form['pause'] = [
78       '#type' => 'checkbox',
79       '#title' => $this->t('Pause on hover'),
80       '#description' => t('Pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave.'),
81       '#default_value' => $this->options['pause'],
82     ];
83
84     $form['wrap'] = [
85       '#type' => 'checkbox',
86       '#title' => $this->t('Wrap'),
87       '#description' => t('The carousel should cycle continuously or have hard stops.'),
88       '#default_value' => $this->options['wrap'],
89     ];
90
91     $form['image'] = [
92       '#type' => 'select',
93       '#title' => $this->t('Image'),
94       '#options' => $fields,
95       '#default_value' => $this->options['image'],
96     ];
97
98     $form['title'] = [
99       '#type' => 'select',
100       '#title' => $this->t('Title'),
101       '#options' => $fields,
102       '#default_value' => $this->options['title'],
103     ];
104
105     $form['description'] = [
106       '#type' => 'select',
107       '#title' => $this->t('Description'),
108       '#options' => $fields,
109       '#default_value' => $this->options['description'],
110     ];
111   }
112
113 }