class PagerManager implements PagerManagerInterface (View source)

Provides a manager for pagers.

Pagers are cached, and can be retrieved when rendering.

Traits

Provides dependency injection friendly methods for serialization.

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected PagerParametersInterface $pagerParams

The pager parameters.

protected array $pagers

An associative array of pagers.

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(PagerParametersInterface $pager_params)

Construct a PagerManager object.

createPager(int $total, int $limit, int $element = 0)

Initializes a pager.

Pager|null
getPager(int $element = 0)

Gets a pager from the static cache.

array
getUpdatedParameters(array $query, int $element, int $index)

Gets the URL query parameter array of a pager link.

int
getMaxPagerElementId()

Gets the extent of the pager page element IDs.

setPager(Pager $pager, int $element = 0)

Saves a pager to the static cache.

updateGlobals()

Updates global variables with a pager data for backwards compatibility.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(PagerParametersInterface $pager_params)

Construct a PagerManager object.

Parameters

PagerParametersInterface $pager_params

The pager parameters.

Pager createPager(int $total, int $limit, int $element = 0)

Initializes a pager.

This function sets up the necessary variables so that the render system will correctly process #type 'pager' render arrays to output pagers that correspond to the items being displayed.

If the items being displayed result from a database query performed using Drupal's database API, and if you have control over the construction of the database query, you do not need to call this function directly; instead, you can extend the query object with the 'PagerSelectExtender' extender before executing it. For example:

Parameters

int $total

The total number of items to be paged.

int $limit

The number of items the calling code will display per page.

int $element

(optional) An integer to distinguish between multiple pagers on one page.

Return Value

Pager

The pager.

Pager|null getPager(int $element = 0)

Gets a pager from the static cache.

Parameters

int $element

The pager element index.

Return Value

Pager|null

The pager, or null if not found.

array getUpdatedParameters(array $query, int $element, int $index)

Gets the URL query parameter array of a pager link.

Adds to or adjusts the 'page' URL query parameter so that if you follow the link, you'll get page $index for pager $element on the page.

The 'page' URL query parameter is a comma-delimited string, where each value is the target content page for the corresponding pager $element. For instance, if we have 5 pagers on a single page, and we want to have a link to a page that should display the 6th content page for the 3rd pager, and the 1st content page for all the other pagers, then the URL query will look like this: ?page=0,0,5,0,0 (page numbering starts at zero).

Parameters

array $query

An associative array of URL query parameters to add to.

int $element

An integer to distinguish between multiple pagers on one page.

int $index

The index of the target page, for the given element, in the pager array.

Return Value

array

The altered $query parameter array.

protected int getMaxPagerElementId()

Gets the extent of the pager page element IDs.

Return Value

int

The maximum element ID available, -1 if there are no elements.

protected setPager(Pager $pager, int $element = 0)

Saves a pager to the static cache.

Parameters

Pager $pager

The pager.

int $element

The pager index.

protected updateGlobals()

Updates global variables with a pager data for backwards compatibility.