Commit 82a4f7e7 authored by jaredsmith's avatar jaredsmith

Create a country cache context per d.o issue 2571393

parent 33ce6ceb
......@@ -33,3 +33,8 @@ services:
class: Drupal\commerce\AvailabilityManager
tags:
- { name: service_collector, tag: commerce.availability_checker, call: addChecker }
cache_context.commerce.country
class: Drupal\commerce\Cache\Context\CountryCacheContext
arguments: ['@commerce.country_context']
tags:
- { name: cache.context}
<?php
/**
* @file
* Contains \Drupal\commerce\Cache\Context\CountryCacheContext
*/
namespace Drupal\commerce\Cache\Context;
use Drupal\commerce\CountryContext;
/**
* Defines the CountryCacheContext object, for "per country" caching.
*
* Cache context ID: 'country'.
*/
class CountryCacheContext implements CacheContextInterface {
/**
* The country context.
*
* @var \Drupal\commerce\CountryContext
*/
protected $countryContext;
/**
* Constructs a new CountryCacheContext object.
*
* @param \Drupal\commerce\CountryContext $context
* The country context.
*/
public function __construct(CountryContext $context) {
$this->countryContext = $context;
}
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Country');
}
/**
* {@inheritdoc}
*/
public function getContext() {
return $this->countryContext->getCountry()->getCountryCode();
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment