Create a country cache context

Created on 19 September 2015, over 9 years ago
Updated 16 February 2025, about 2 months ago

We need to provide a country cache context.

Drupal says:

Cache contexts are services tagged with 'cache.context', whose classes implement \Drupal\Core\Cache\Context\CacheContextInterface.
See https://www.drupal.org/developing/api/8/cache/contexts for more information on cache contexts, including a list of the contexts that exist in Drupal core, and information on how to define your own contexts.

Core service we should use as an example:

  cache_context.theme:
    class: Drupal\Core\Cache\Context\ThemeCacheContext
    arguments: ['@theme.manager']
    tags:
      - { name: cache.context}

We need:
1) An entry in commerce.services.yml
2) The src/Cache/Context/CountryCacheContext class.
The CountryCacheContext needs to take the CountryContext as a dependency, and return the resolved country code in getContext().

📌 Task
Status

Fixed

Version

2.0

Component

Developer experience

Created by

🇷🇸Serbia bojanz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024