3 namespace Drupal\views\Plugin\views\pager;
5 use Drupal\Core\Form\FormStateInterface;
8 * Plugin for views without pagers.
10 * @ingroup views_pager_plugins
14 * title = @Translation("Display a specified number of items"),
15 * help = @Translation("Display a limited number items that this view might find."),
16 * display_types = {"basic"}
19 class Some extends PagerPluginBase {
21 public function summaryTitle() {
22 if (!empty($this->options['offset'])) {
23 return $this->formatPlural($this->options['items_per_page'], '@count item, skip @skip', '@count items, skip @skip', ['@count' => $this->options['items_per_page'], '@skip' => $this->options['offset']]);
25 return $this->formatPlural($this->options['items_per_page'], '@count item', '@count items', ['@count' => $this->options['items_per_page']]);
28 protected function defineOptions() {
29 $options = parent::defineOptions();
30 $options['items_per_page'] = ['default' => 10];
31 $options['offset'] = ['default' => 0];
37 * Provide the default form for setting options.
39 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
40 parent::buildOptionsForm($form, $form_state);
41 $pager_text = $this->displayHandler->getPagerText();
42 $form['items_per_page'] = [
43 '#title' => $pager_text['items per page title'],
44 '#type' => 'textfield',
45 '#description' => $pager_text['items per page description'],
46 '#default_value' => $this->options['items_per_page'],
50 '#type' => 'textfield',
51 '#title' => $this->t('Offset (number of items to skip)'),
52 '#description' => $this->t('For example, set this to 3 and the first 3 items will not be displayed.'),
53 '#default_value' => $this->options['offset'],
57 public function usePager() {
61 public function useCountQuery() {
65 public function query() {
66 $this->view->query->setLimit($this->options['items_per_page']);
67 $this->view->query->setOffset($this->options['offset']);