Version 1
[yaffs-website] / web / core / modules / views / src / Plugin / views / pager / None.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\pager;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\ViewExecutable;
7 use Drupal\views\Plugin\views\display\DisplayPluginBase;
8
9 /**
10  * Plugin for views without pagers.
11  *
12  * @ingroup views_pager_plugins
13  *
14  * @ViewsPager(
15  *   id = "none",
16  *   title = @Translation("Display all items"),
17  *   help = @Translation("Display all items that this view might find."),
18  *   display_types = {"basic"}
19  * )
20  */
21 class None extends PagerPluginBase {
22
23   /**
24    * {@inheritdoc}
25    */
26   public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
27     parent::init($view, $display, $options);
28
29     // If the pager is set to none, then it should show all items.
30     $this->setItemsPerPage(0);
31   }
32
33   public function summaryTitle() {
34     if (!empty($this->options['offset'])) {
35       return $this->t('All items, skip @skip', ['@skip' => $this->options['offset']]);
36     }
37     return $this->t('All items');
38   }
39
40   protected function defineOptions() {
41     $options = parent::defineOptions();
42     $options['offset'] = ['default' => 0];
43
44     return $options;
45   }
46
47   /**
48    * Provide the default form for setting options.
49    */
50   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
51     parent::buildOptionsForm($form, $form_state);
52     $form['offset'] = [
53       '#type' => 'textfield',
54       '#title' => $this->t('Offset (number of items to skip)'),
55       '#description' => $this->t('For example, set this to 3 and the first 3 items will not be displayed.'),
56       '#default_value' => $this->options['offset'],
57     ];
58   }
59
60   public function usePager() {
61     return FALSE;
62   }
63
64   public function useCountQuery() {
65     return FALSE;
66   }
67
68   public function getItemsPerPage() {
69     return 0;
70   }
71
72   public function executeCountQuery(&$count_query) {
73     // If we are displaying all items, never count. But we can update the count in post_execute.
74   }
75
76   public function postExecute(&$result) {
77     $this->total_items = count($result);
78   }
79
80   public function query() {
81     // The only query modifications we might do are offsets.
82     if (!empty($this->options['offset'])) {
83       $this->view->query->setOffset($this->options['offset']);
84     }
85   }
86
87 }