Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / views_bootstrap / src / Plugin / views / style / ViewsBootstrapTab.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 use Drupal\views_bootstrap\ViewsBootstrap;
8
9 /**
10  * Style plugin to render each item in an ordered or unordered list.
11  *
12  * @ingroup views_style_plugins
13  *
14  * @ViewsStyle(
15  *   id = "views_bootstrap_tab",
16  *   title = @Translation("Bootstrap Tab"),
17  *   help = @Translation("Displays rows in Bootstrap Tabs."),
18  *   theme = "views_bootstrap_tab",
19  *   theme_file = "../views_bootstrap.theme.inc",
20  *   display_types = {"normal"}
21  * )
22  */
23 class ViewsBootstrapTab extends StylePluginBase {
24
25   /**
26    * Does the style plugin for itself support to add fields to it's output.
27    *
28    * @var bool
29    */
30   protected $usesFields = TRUE;
31
32   /**
33    * {@inheritdoc}
34    */
35   protected $usesOptions = TRUE;
36   protected $usesRowPlugin = TRUE;
37
38   /**
39    * Definition.
40    */
41   protected function defineOptions() {
42     $options = parent::defineOptions();
43     $options['tab_field'] = ['default' => NULL];
44     $options['tab_type'] = ['default' => 'tabs'];
45     $options['justified'] = ['default' => FALSE];
46     return $options;
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
53     parent::buildOptionsForm($form, $form_state);
54     if (isset($form['grouping'])) {
55       unset($form['grouping']);
56
57       $form['tab_field'] = [
58         '#type' => 'select',
59         '#title' => $this->t('Tab field'),
60         '#options' => $this->displayHandler->getFieldLabels(TRUE),
61         '#required' => TRUE,
62         '#default_value' => $this->options['tab_field'],
63         '#description' => t('Select the field that will be used as the tab.'),
64       ];
65
66       $form['tab_type'] = [
67         '#type' => 'select',
68         '#title' => $this->t('Tab Type'),
69         '#options' => [
70           'tabs' => $this->t('Tabs'),
71           'pills' => $this->t('Pills'),
72           'list' => $this->t('List'),
73         ],
74         '#required' => TRUE,
75         '#default_value' => $this->options['tab_type'],
76       ];
77
78       $form['justified'] = [
79         '#type' => 'checkbox',
80         '#title' => $this->t('Justified'),
81         '#default_value' => $this->options['justified'],
82         '#description' => $this->t('Make tabs equal widths of their parent'),
83       ];
84     }
85
86   }
87
88 }