The pager calculations are now done by the pager.manager service.
The following global variables are deprecated:
$pager_limits$pager_page_array$pager_total$pager_total_items
The following functions are deprecated:
pager_find_page()pager_default_initialize()pager_get_query_parameters()pager_query_add_page()
These have been replaced by the pager.manager service, which implements Drupal\Core\Pager\PagerManagerInterface.
It exposes the following methods which are easy replacements for the global functions:
PagerManagerInterface::createPager()PagerManagerInterface::getPager()PagerManagerInterface::getUpdatedParameters()
In Drupal 8.8.0 onwards this service updates the deprecated global variables in order to provide backwards-compatibility. In Drupal 9, these global variables will be removed.
The 'pager.parameters' service which implements \Drupal\Core\Pager\PagerParametersInterface provides the following methods for extracting pager information from the request query string:
\Drupal\Core\Pager\PagerParametersInterface::findPage()\Drupal\Core\Pager\PagerParametersInterface::getQueryParameters()\Drupal\Core\Pager\PagerParametersInterface::getPagerQuery()\Drupal\Core\Pager\PagerParametersInterface::getPagerParameter()
Comments
my 2 cents
spent a lot of time in order to understand this
\Drupal::service('pager.manager')->createPager($total_count, $results_in_page);the page number will be retrieved by the query parameter page <-- hard coded! (which in my opinion it should not be, or at least be able to set it)
than
can be renderd by
or as part as the return array:
Example
This is what the global variable replacement looks like in a custom module: