function Pager::preRenderPager

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/Element/Pager.php \Drupal\Core\Render\Element\Pager::preRenderPager()
  2. 8.9.x core/lib/Drupal/Core/Render/Element/Pager.php \Drupal\Core\Render\Element\Pager::preRenderPager()
  3. 11.x core/lib/Drupal/Core/Render/Element/Pager.php \Drupal\Core\Render\Element\Pager::preRenderPager()

#pre_render callback to associate the appropriate cache context.

Parameters

array $pager: A renderable array of #type => pager.

Return value

array

File

core/lib/Drupal/Core/Render/Element/Pager.php, line 73

Class

Pager
Provides a render element for a pager.

Namespace

Drupal\Core\Render\Element

Code

public static function preRenderPager(array $pager) {
    // Note: the default pager theme process function
    // template_preprocess_pager() also calls
    // \Drupal\Core\Pager\PagerManagerInterface::getUpdatedParameters(), which
    // maintains the existing query string. Therefore
    // template_preprocess_pager() adds the 'url.query_args' cache context,
    // which causes the more specific cache context below to be optimized away.
    // In other themes, however, that may not be the case.
    $pager['#cache']['contexts'][] = 'url.query_args.pagers:' . $pager['#element'];
    return $pager;
}

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