3 namespace Drupal\Core\Cache\Context;
5 use Drupal\Core\Cache\CacheableMetadata;
8 * Defines the CookiesCacheContext service, for "per cookie" caching.
10 * Cache context ID: 'cookies' (to vary by all cookies).
11 * Calculated cache context ID: 'cookies:%name', e.g. 'cookies:device_type' (to
12 * vary by the 'device_type' cookie).
14 class CookiesCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface {
19 public static function getLabel() {
20 return t('HTTP cookies');
26 public function getContext($cookie = NULL) {
27 if ($cookie === NULL) {
28 return $this->requestStack->getCurrentRequest()->cookies->all();
31 return $this->requestStack->getCurrentRequest()->cookies->get($cookie);
38 public function getCacheableMetadata($cookie = NULL) {
39 return new CacheableMetadata();