3 namespace Drupal\Core\Cache\Context;
5 use Drupal\Core\Cache\CacheableMetadata;
8 * Defines a cache context for "per page in a pager" caching.
10 * Cache context ID: 'url.query_args.pagers' (to vary by all pagers).
11 * Calculated cache context ID: 'url.query_args.pagers:%pager_id', e.g.
12 * 'url.query_args.pagers:1' (to vary by the pager with ID 1).
14 class PagersCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface {
19 public static function getLabel() {
26 * @see pager_find_page()
28 public function getContext($pager_id = NULL) {
29 // The value of the 'page' query argument contains the information that
30 // controls *all* pagers.
31 if ($pager_id === NULL) {
32 return $this->requestStack->getCurrentRequest()->query->get('page', '');
35 return $pager_id . '.' . pager_find_page($pager_id);
41 public function getCacheableMetadata($pager_id = NULL) {
42 return new CacheableMetadata();