d2cbed944e1d5e7bf82756478c62ff8441e7a36a
[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
37   /**
38    * Definition.
39    */
40   protected function defineOptions() {
41     $options = parent::defineOptions();
42     $options['tab_field'] = ['default' => NULL];
43     $options['tab_type'] = ['default' => 'tabs'];
44     $options['justified'] = ['default' => FALSE];
45     return $options;
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
52     parent::buildOptionsForm($form, $form_state);
53     if (isset($form['grouping'])) {
54       unset($form['grouping']);
55
56       $form['tab_field'] = [
57         '#type' => 'select',
58         '#title' => $this->t('Tab field'),
59         '#options' => $this->displayHandler->getFieldLabels(TRUE),
60         '#required' => TRUE,
61         '#default_value' => $this->options['tab_field'],
62         '#description' => t('Select the field that will be used as the tab.'),
63       ];
64
65       $form['tab_type'] = [
66         '#type' => 'select',
67         '#title' => $this->t('Tab Type'),
68         '#options' => [
69           'tabs' => $this->t('Tabs'),
70           'pills' => $this->t('Pills'),
71           'list' => $this->t('List'),
72         ],
73         '#required' => TRUE,
74         '#default_value' => $this->options['tab_type'],
75       ];
76
77       $form['justified'] = [
78         '#type' => 'checkbox',
79         '#title' => $this->t('Justified'),
80         '#default_value' => $this->options['justified'],
81         '#description' => $this->t('Make tabs equal widths of their parent'),
82       ];
83     }
84
85   }
86
87 }