Version 1
[yaffs-website] / web / core / modules / views / src / Plugin / views / pager / Full.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\pager;
4
5 use Drupal\Core\Form\FormStateInterface;
6
7 /**
8  * The plugin to handle full pager.
9  *
10  * @ingroup views_pager_plugins
11  *
12  * @ViewsPager(
13  *   id = "full",
14  *   title = @Translation("Paged output, full pager"),
15  *   short_title = @Translation("Full"),
16  *   help = @Translation("Paged output, full Drupal style"),
17  *   theme = "pager",
18  *   register_theme = FALSE
19  * )
20  */
21 class Full extends SqlBase {
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function defineOptions() {
27     $options = parent::defineOptions();
28
29     // Use the same default quantity that core uses by default.
30     $options['quantity'] = ['default' => 9];
31
32     $options['tags']['contains']['first'] = ['default' => $this->t('« First')];
33     $options['tags']['contains']['last'] = ['default' => $this->t('Last »')];
34
35     return $options;
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
42     parent::buildOptionsForm($form, $form_state);
43
44     $form['quantity'] = [
45       '#type' => 'number',
46       '#title' => $this->t('Number of pager links visible'),
47       '#description' => $this->t('Specify the number of links to pages to display in the pager.'),
48       '#default_value' => $this->options['quantity'],
49     ];
50
51     $form['tags']['first'] = [
52       '#type' => 'textfield',
53       '#title' => $this->t('First page link text'),
54       '#default_value' => $this->options['tags']['first'],
55       '#weight' => -10,
56     ];
57
58     $form['tags']['last'] = [
59       '#type' => 'textfield',
60       '#title' => $this->t('Last page link text'),
61       '#default_value' => $this->options['tags']['last'],
62       '#weight' => 10,
63     ];
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function summaryTitle() {
70     if (!empty($this->options['offset'])) {
71       return $this->formatPlural($this->options['items_per_page'], '@count item, skip @skip', 'Paged, @count items, skip @skip', ['@count' => $this->options['items_per_page'], '@skip' => $this->options['offset']]);
72     }
73     return $this->formatPlural($this->options['items_per_page'], '@count item', 'Paged, @count items', ['@count' => $this->options['items_per_page']]);
74   }
75
76   /**
77    * {@inheritdoc}
78    */
79   public function render($input) {
80     // The 0, 1, 3, 4 indexes are correct. See the template_preprocess_pager()
81     // documentation.
82     $tags = [
83       0 => $this->options['tags']['first'],
84       1 => $this->options['tags']['previous'],
85       3 => $this->options['tags']['next'],
86       4 => $this->options['tags']['last'],
87     ];
88     return [
89       '#theme' => $this->themeFunctions(),
90       '#tags' => $tags,
91       '#element' => $this->options['id'],
92       '#parameters' => $input,
93       '#quantity' => $this->options['quantity'],
94       '#route_name' => !empty($this->view->live_preview) ? '<current>' : '<none>',
95     ];
96   }
97
98 }