Version 1
[yaffs-website] / web / core / lib / Drupal / Core / Cache / Context / PagersCacheContext.php
1 <?php
2
3 namespace Drupal\Core\Cache\Context;
4
5 use Drupal\Core\Cache\CacheableMetadata;
6
7 /**
8  * Defines a cache context for "per page in a pager" caching.
9  *
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).
13  */
14 class PagersCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface {
15
16   /**
17    * {@inheritdoc}
18    */
19   public static function getLabel() {
20     return t('Pager');
21   }
22
23   /**
24    * {@inheritdoc}
25    *
26    * @see pager_find_page()
27    */
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', '');
33     }
34
35     return $pager_id . '.' . pager_find_page($pager_id);
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function getCacheableMetadata($pager_id = NULL) {
42     return new CacheableMetadata();
43   }
44
45 }