class Pager

Same name in this branch
  1. 10 core/lib/Drupal/Core/Render/Element/Pager.php \Drupal\Core\Render\Element\Pager
Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/Element/Pager.php \Drupal\Core\Render\Element\Pager
  2. 9 core/lib/Drupal/Core/Pager/Pager.php \Drupal\Core\Pager\Pager
  3. 8.9.x core/lib/Drupal/Core/Render/Element/Pager.php \Drupal\Core\Render\Element\Pager
  4. 8.9.x core/lib/Drupal/Core/Pager/Pager.php \Drupal\Core\Pager\Pager
  5. 11.x core/lib/Drupal/Core/Render/Element/Pager.php \Drupal\Core\Render\Element\Pager
  6. 11.x core/lib/Drupal/Core/Pager/Pager.php \Drupal\Core\Pager\Pager

A value object that represents a pager.

Hierarchy

  • class \Drupal\Core\Pager\Pager

Expanded class hierarchy of Pager

42 string references to 'Pager'
AreaDisplayLinkTest::assertWarningMessages in core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php
Assert the warning messages are shown after changing the page_1 display.
AreaDisplayLinkTest::setUp in core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php
AreaDisplayLinkTest::testAreaDisplayLink in core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php
Tests the views area display_link handler.
Attachment::attachTo in core/modules/views/src/Plugin/views/display/Attachment.php
Allows displays to attach to other views.
Attachment::optionsSummary in core/modules/views/src/Plugin/views/display/Attachment.php
Provide the summary for attachment options in the views UI.

... See full list

File

core/lib/Drupal/Core/Pager/Pager.php, line 8

Namespace

Drupal\Core\Pager
View source
class Pager {
    
    /**
     * The total number of items .
     *
     * @var int
     */
    protected $totalItems;
    
    /**
     * The total number of pages.
     *
     * @var int
     */
    protected $totalPages;
    
    /**
     * The current page of the pager.
     *
     * @var int
     */
    protected $currentPage;
    
    /**
     * The maximum number of items per page.
     *
     * @var int
     */
    protected $limit;
    
    /**
     * Pager constructor.
     *
     * @param int $totalItems
     *   The total number of items.
     * @param int $limit
     *   The maximum number of items per page.
     * @param int $currentPage
     *   The current page.
     */
    public function __construct($totalItems, $limit, $currentPage = 0) {
        $this->totalItems = $totalItems;
        $this->limit = $limit;
        $this->setTotalPages($totalItems, $limit);
        $this->setCurrentPage($currentPage);
    }
    
    /**
     * Sets the current page to a valid value within range.
     *
     * If a page that does not correspond to the actual range of the result set
     * was provided, this function will set the closest page actually within
     * the result set.
     *
     * @param int $currentPage
     *   (optional) The current page.
     */
    protected function setCurrentPage($currentPage = 0) {
        $this->currentPage = max(0, min($currentPage, $this->getTotalPages() - 1));
    }
    
    /**
     * Sets the total number of pages.
     *
     * @param int $totalItems
     *   The total number of items.
     * @param int $limit
     *   The maximum number of items per page.
     */
    protected function setTotalPages($totalItems, $limit) {
        $this->totalPages = (int) ceil($totalItems / $limit);
    }
    
    /**
     * Gets the total number of items.
     *
     * @return int
     *   The total number of items.
     */
    public function getTotalItems() {
        return $this->totalItems;
    }
    
    /**
     * Gets the total number of pages.
     *
     * @return int
     *   The total number of pages.
     */
    public function getTotalPages() {
        return $this->totalPages;
    }
    
    /**
     * Gets the current page.
     *
     * @return int
     *   The current page.
     */
    public function getCurrentPage() {
        return $this->currentPage;
    }
    
    /**
     * Gets the maximum number of items per page.
     *
     * @return int
     *   The maximum number of items per page.
     */
    public function getLimit() {
        return $this->limit;
    }

}

Members

Title Sort descending Modifiers Object type Summary
Pager::$currentPage protected property The current page of the pager.
Pager::$limit protected property The maximum number of items per page.
Pager::$totalItems protected property The total number of items .
Pager::$totalPages protected property The total number of pages.
Pager::getCurrentPage public function Gets the current page.
Pager::getLimit public function Gets the maximum number of items per page.
Pager::getTotalItems public function Gets the total number of items.
Pager::getTotalPages public function Gets the total number of pages.
Pager::setCurrentPage protected function Sets the current page to a valid value within range.
Pager::setTotalPages protected function Sets the total number of pages.
Pager::__construct public function Pager constructor.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.