3 namespace Drupal\views_bootstrap\Plugin\views\style;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\style\StylePluginBase;
9 * Style plugin to render each item as a row in a Bootstrap Carousel.
11 * @ingroup views_style_plugins
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"}
22 class ViewsBootstrapCarousel extends StylePluginBase {
24 * Does the style plugin for itself support to add fields to it's output.
28 protected $usesFields = TRUE;
33 protected function defineOptions() {
34 $options = parent::defineOptions();
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];
42 $options['image'] = ['default' => ''];
43 $options['title'] = ['default' => ''];
44 $options['description'] = ['default' => ''];
50 * Render the given style.
52 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
53 parent::buildOptionsForm($form, $form_state);
55 $fields = ['' => t('<None>')];
56 $fields += $this->displayHandler->getFieldLabels(TRUE);
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'],
65 $form['navigation'] = [
66 '#type' => 'checkbox',
67 '#title' => $this->t('Show navigation'),
68 '#default_value' => $this->options['navigation'],
71 $form['indicators'] = [
72 '#type' => 'checkbox',
73 '#title' => $this->t('Show indicators'),
74 '#default_value' => $this->options['indicators'],
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'],
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'],
93 '#title' => $this->t('Image'),
94 '#options' => $fields,
95 '#default_value' => $this->options['image'],
100 '#title' => $this->t('Title'),
101 '#options' => $fields,
102 '#default_value' => $this->options['title'],
105 $form['description'] = [
107 '#title' => $this->t('Description'),
108 '#options' => $fields,
109 '#default_value' => $this->options['description'],