function QueryBase::pager

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::pager()
  2. 8.9.x core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::pager()
  3. 11.x core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::pager()

Enables a pager for the query.

Parameters

int $limit: (optional) An integer specifying the number of elements per page. If passed 0, the pager is disabled.

int|null $element: (optional) An integer to distinguish between multiple pagers on one page. If not provided, one is automatically calculated by incrementing the next pager element value.

Return value

$this

Overrides QueryInterface::pager

File

core/lib/Drupal/Core/Entity/Query/QueryBase.php, line 292

Class

QueryBase
The base entity query class.

Namespace

Drupal\Core\Entity\Query

Code

public function pager($limit = 10, $element = NULL) {
    // Even when not using SQL, storing the element PagerSelectExtender is as
    // good as anywhere else.
    if (!isset($element)) {
        $element = \Drupal::service('pager.manager')->getMaxPagerElementId() + 1;
    }
    $this->pager = [
        'limit' => $limit,
        'element' => $element,
    ];
    return $this;
}

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