comparison modules/contrib/views_slideshow/src/Plugin/ViewsSlideshowWidget/PagerFields.php @ 5:c69a71b4f40f

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