negotiator = $negotiator; } /** * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { // Load the current domain. $current_domain = $this->negotiator->getActiveDomain(); // Set the context. $context = new Context(new ContextDefinition('entity:domain', $this->t('Active domain')), $current_domain); // Allow caching. $cacheability = new CacheableMetadata(); $cacheability->setCacheContexts(['url.site']); $context->addCacheableDependency($cacheability); // Prepare the result. $result = [ 'entity:domain' => $context, ]; return $result; } /** * {@inheritdoc} */ public function getAvailableContexts() { $context = new Context(new ContextDefinition('entity:domain', $this->t('Active domain'))); return ['entity:domain' => $context]; } }