function SqlBase::updatePageInfo

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/pager/SqlBase.php \Drupal\views\Plugin\views\pager\SqlBase::updatePageInfo()
  2. 8.9.x core/modules/views/src/Plugin/views/pager/SqlBase.php \Drupal\views\Plugin\views\pager\SqlBase::updatePageInfo()
  3. 10 core/modules/views/src/Plugin/views/pager/SqlBase.php \Drupal\views\Plugin\views\pager\SqlBase::updatePageInfo()

Update global paging info.

This is called after the count query has been run to set the total items available and to update the current page if the requested page is out of range.

Overrides PagerPluginBase::updatePageInfo

File

core/modules/views/src/Plugin/views/pager/SqlBase.php, line 332

Class

SqlBase
A common base class for sql based pager.

Namespace

Drupal\views\Plugin\views\pager

Code

public function updatePageInfo() {
    if (!empty($this->options['total_pages'])) {
        if ($this->options['total_pages'] * $this->options['items_per_page'] < $this->total_items) {
            $this->total_items = $this->options['total_pages'] * $this->options['items_per_page'];
        }
    }
    // Don't set pager settings for items per page = 0.
    $items_per_page = $this->getItemsPerPage();
    if (!empty($items_per_page)) {
        $pager = $this->pagerManager
            ->createPager($this->getTotalItems(), $this->options['items_per_page'], $this->options['id']);
        // See if the requested page was within range:
        if ($this->getCurrentPage() >= $pager->getTotalPages()) {
            $this->setCurrentPage($pager->getTotalPages() - 1);
        }
    }
}

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