3 namespace Drupal\Core\Render\Element;
6 * Provides a render element for a pager.
8 * The pager must be initialized with a call to pager_default_initialize() in
9 * order to render properly. When used with database queries, this is performed
10 * for you when you extend a select query with
11 * \Drupal\Core\Database\Query\PagerSelectExtender.
14 * - #element: (optional, int) The pager ID, to distinguish between multiple
15 * pagers on the same page (defaults to 0).
16 * - #parameters: (optional) An associative array of query string parameters to
17 * append to the pager.
18 * - #quantity: The maximum number of numbered page links to create (defaults
20 * - #tags: (optional) An array of labels for the controls in the pages.
21 * - #route_name: (optional) The name of the route to be used to build pager
22 * links. Defaults to '<none>', which will make links relative to the current
23 * URL. This makes the page more effectively cacheable.
31 * @RenderElement("pager")
33 class Pager extends RenderElement {
38 public function getInfo() {
41 get_class($this) . '::preRenderPager',
44 // The pager ID, to distinguish between multiple pagers on the same page.
46 // An associative array of query string parameters to append to the pager
49 // The number of pages in the list.
51 // An array of labels for the controls in the pager.
53 // The name of the route to be used to build pager links. By default no
54 // path is provided, which will make links relative to the current URL.
55 // This makes the page more effectively cacheable.
56 '#route_name' => '<none>',
61 * #pre_render callback to associate the appropriate cache context.
65 * A renderable array of #type => pager.
69 public static function preRenderPager(array $pager) {
70 // Note: the default pager theme process function
71 // template_preprocess_pager() also calls pager_query_add_page(), which
72 // maintains the existing query string. Therefore
73 // template_preprocess_pager() adds the 'url.query_args' cache context,
74 // which causes the more specific cache context below to be optimized away.
75 // In other themes, however, that may not be the case.
76 $pager['#cache']['contexts'][] = 'url.query_args.pagers:' . $pager['#element'];