class CountryCacheContext in Commerce Core 8.2
Defines the country cache context, for "per country" caching.
Cache context ID: 'country'.
Hierarchy
- class \Drupal\commerce\Cache\Context\CountryCacheContext implements CacheContextInterface
Expanded class hierarchy of CountryCacheContext
1 string reference to 'CountryCacheContext'
1 service uses CountryCacheContext
File
- src/
Cache/ Context/ CountryCacheContext.php, line 14
Namespace
Drupal\commerce\Cache\ContextView source
class CountryCacheContext implements CacheContextInterface {
/**
* The current country.
*
* @var \Drupal\commerce\CurrentCountry
*/
protected $currentCountry;
/**
* Constructs a new CountryCacheContext object.
*
* @param \Drupal\commerce\CurrentCountry $country
* The current country.
*/
public function __construct(CurrentCountry $country) {
$this->currentCountry = $country;
}
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Country');
}
/**
* {@inheritdoc}
*/
public function getContext() {
return $this->currentCountry
->getCountry()
->getCountryCode();
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CountryCacheContext:: |
protected | property | The current country. | |
CountryCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
CountryCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
CountryCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
CountryCacheContext:: |
public | function | Constructs a new CountryCacheContext object. |