You are here

class RngEventCacheContext in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/Cache/Context/RngEventCacheContext.php \Drupal\rng\Cache\Context\RngEventCacheContext
  2. 8 src/Cache/Context/RngEventCacheContext.php \Drupal\rng\Cache\Context\RngEventCacheContext

A context for the current rng_event.

Cache context ID: 'rng_event'.

Hierarchy

Expanded class hierarchy of RngEventCacheContext

1 string reference to 'RngEventCacheContext'
rng.services.yml in ./rng.services.yml
rng.services.yml
1 service uses RngEventCacheContext
cache_context.rng_event in ./rng.services.yml
Drupal\rng\Cache\Context\RngEventCacheContext

File

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

Namespace

Drupal\rng\Cache\Context
View source
class RngEventCacheContext implements CacheContextInterface {

  /**
   * The RNG event from the current route.
   *
   * @var \Drupal\Core\Entity\EntityInterface
   */
  protected $rng_event;

  /**
   * Constructs a new RngEventCacheContext service..
   *
   * @param \Drupal\Core\Plugin\Context\ContextProviderInterface $context_provider
   *   The rng_event context service.
   */
  public function __construct(ContextProviderInterface $context_provider) {

    /** @var \Drupal\rng\ContextProvider\RngEventRouteContext $context_provider */
    $contexts = $context_provider
      ->getRuntimeContexts([
      'rng_event',
    ]);
    $this->rng_event = $contexts['rng_event']
      ->getContextValue();
  }

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('RNG Event');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    if (isset($this->rng_event)) {
      return $this->rng_event
        ->getEntityTypeId() . ':' . $this->rng_event
        ->id();
    }
    return '';
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RngEventCacheContext::$rng_event protected property The RNG event from the current route.
RngEventCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
RngEventCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
RngEventCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
RngEventCacheContext::__construct public function Constructs a new RngEventCacheContext service..