Backup of db before drupal security update
[yaffs-website] / web / core / modules / views / src / Plugin / views / style / DefaultSummary.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\style;
4
5 use Drupal\Core\Form\FormStateInterface;
6
7 /**
8  * The default style plugin for summaries.
9  *
10  * @ingroup views_style_plugins
11  *
12  * @ViewsStyle(
13  *   id = "default_summary",
14  *   title = @Translation("List"),
15  *   help = @Translation("Displays the default summary as a list."),
16  *   theme = "views_view_summary",
17  *   display_types = {"summary"}
18  * )
19  */
20 class DefaultSummary extends StylePluginBase {
21
22   protected function defineOptions() {
23     $options = parent::defineOptions();
24
25     $options['base_path'] = ['default' => ''];
26     $options['count'] = ['default' => TRUE];
27     $options['override'] = ['default' => FALSE];
28     $options['items_per_page'] = ['default' => 25];
29
30     return $options;
31   }
32
33   public function query() {
34     if (!empty($this->options['override'])) {
35       $this->view->setItemsPerPage(intval($this->options['items_per_page']));
36     }
37   }
38
39   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
40     $form['base_path'] = [
41       '#type' => 'textfield',
42       '#title' => $this->t('Base path'),
43       '#default_value' => $this->options['base_path'],
44       '#description' => $this->t('Define the base path for links in this summary
45         view, i.e. http://example.com/<strong>your_view_path/archive</strong>.
46         Do not include beginning and ending forward slash. If this value
47         is empty, views will use the first path found as the base path,
48         in page displays, or / if no path could be found.'),
49     ];
50     $form['count'] = [
51       '#type' => 'checkbox',
52       '#default_value' => !empty($this->options['count']),
53       '#title' => $this->t('Display record count with link'),
54     ];
55     $form['override'] = [
56       '#type' => 'checkbox',
57       '#default_value' => !empty($this->options['override']),
58       '#title' => $this->t('Override number of items to display'),
59     ];
60
61     $form['items_per_page'] = [
62       '#type' => 'textfield',
63       '#title' => $this->t('Items to display'),
64       '#default_value' => $this->options['items_per_page'],
65       '#states' => [
66         'visible' => [
67           ':input[name="options[summary][options][' . $this->definition['id'] . '][override]"]' => ['checked' => TRUE],
68         ],
69       ],
70     ];
71   }
72
73   public function render() {
74     $rows = [];
75     foreach ($this->view->result as $row) {
76       // @todo: Include separator as an option.
77       $rows[] = $row;
78     }
79
80     return [
81       '#theme' => $this->themeFunctions(),
82       '#view' => $this->view,
83       '#options' => $this->options,
84       '#rows' => $rows,
85     ];
86   }
87
88 }