"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/views/src/Plugin/views/pager/None.php" (26 Nov 2020, 2253 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "None.php" see the Fossies "Dox" file reference documentation.

    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' => 'number',
   54       '#min' => 0,
   55       '#title' => $this->t('Offset (number of items to skip)'),
   56       '#description' => $this->t('For example, set this to 3 and the first 3 items will not be displayed.'),
   57       '#default_value' => $this->options['offset'],
   58     ];
   59   }
   60 
   61   public function usePager() {
   62     return FALSE;
   63   }
   64 
   65   public function useCountQuery() {
   66     return FALSE;
   67   }
   68 
   69   public function getItemsPerPage() {
   70     return 0;
   71   }
   72 
   73   public function executeCountQuery(&$count_query) {
   74     // If we are displaying all items, never count. But we can update the count in post_execute.
   75   }
   76 
   77   public function postExecute(&$result) {
   78     $this->total_items = count($result);
   79   }
   80 
   81   public function query() {
   82     // The only query modifications we might do are offsets.
   83     if (!empty($this->options['offset'])) {
   84       $this->view->query->setOffset($this->options['offset']);
   85     }
   86   }
   87 
   88 }