a6df09d2b2790d1bc5680f5f70b5aa98411f2f56
[yaffs-website] / web / core / modules / views / src / Plugin / views / style / HtmlList.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\style;
4
5 use Drupal\Core\Form\FormStateInterface;
6
7 /**
8  * Style plugin to render each item in an ordered or unordered list.
9  *
10  * @ingroup views_style_plugins
11  *
12  * @ViewsStyle(
13  *   id = "html_list",
14  *   title = @Translation("HTML List"),
15  *   help = @Translation("Displays rows as HTML list."),
16  *   theme = "views_view_list",
17  *   display_types = {"normal"}
18  * )
19  */
20 class HtmlList extends StylePluginBase {
21
22   /**
23    * Does the style plugin allows to use style plugins.
24    *
25    * @var bool
26    */
27   protected $usesRowPlugin = TRUE;
28
29   /**
30    * Does the style plugin support custom css class for the rows.
31    *
32    * @var bool
33    */
34   protected $usesRowClass = TRUE;
35
36   /**
37    * Set default options
38    */
39   protected function defineOptions() {
40     $options = parent::defineOptions();
41
42     $options['type'] = ['default' => 'ul'];
43     $options['class'] = ['default' => ''];
44     $options['wrapper_class'] = ['default' => 'item-list'];
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     $form['type'] = [
55       '#type' => 'radios',
56       '#title' => $this->t('List type'),
57       '#options' => ['ul' => $this->t('Unordered list'), 'ol' => $this->t('Ordered list')],
58       '#default_value' => $this->options['type'],
59     ];
60     $form['wrapper_class'] = [
61       '#title' => $this->t('Wrapper class'),
62       '#description' => $this->t('The class to provide on the wrapper, outside the list.'),
63       '#type' => 'textfield',
64       '#size' => '30',
65       '#default_value' => $this->options['wrapper_class'],
66     ];
67     $form['class'] = [
68       '#title' => $this->t('List class'),
69       '#description' => $this->t('The class to provide on the list element itself.'),
70       '#type' => 'textfield',
71       '#size' => '30',
72       '#default_value' => $this->options['class'],
73     ];
74   }
75
76 }