You are here

class CountryCacheContext in Price 3.x

Same name and namespace in other branches
  1. 8 src/Cache/Context/CountryCacheContext.php \Drupal\price\Cache\Context\CountryCacheContext
  2. 2.0.x src/Cache/Context/CountryCacheContext.php \Drupal\price\Cache\Context\CountryCacheContext
  3. 2.x src/Cache/Context/CountryCacheContext.php \Drupal\price\Cache\Context\CountryCacheContext
  4. 3.0.x src/Cache/Context/CountryCacheContext.php \Drupal\price\Cache\Context\CountryCacheContext

Defines the country cache context, for "per country" caching.

Cache context ID: 'country'.

Hierarchy

Expanded class hierarchy of CountryCacheContext

1 string reference to 'CountryCacheContext'
price.services.yml in ./price.services.yml
price.services.yml
1 service uses CountryCacheContext
cache_context.price_country in ./price.services.yml
Drupal\price\Cache\Context\CountryCacheContext

File

src/Cache/Context/CountryCacheContext.php, line 14

Namespace

Drupal\price\Cache\Context
View source
class CountryCacheContext implements CacheContextInterface {

  /**
   * The current country.
   *
   * @var \Drupal\price\CurrentCountry
   */
  protected $currentCountry;

  /**
   * Constructs a new CountryCacheContext object.
   *
   * @param \Drupal\price\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

Namesort descending Modifiers Type Description Overrides
CountryCacheContext::$currentCountry protected property The current country.
CountryCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
CountryCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
CountryCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
CountryCacheContext::__construct public function Constructs a new CountryCacheContext object.