You are here

class CurrentDomainContext in Domain Access 8

Provides a context handler for the block system.

Hierarchy

Expanded class hierarchy of CurrentDomainContext

1 string reference to 'CurrentDomainContext'
domain.services.yml in domain/domain.services.yml
domain/domain.services.yml
1 service uses CurrentDomainContext
domain.current_domain_context in domain/domain.services.yml
Drupal\domain\ContextProvider\CurrentDomainContext

File

domain/src/ContextProvider/CurrentDomainContext.php, line 16

Namespace

Drupal\domain\ContextProvider
View source
class CurrentDomainContext implements ContextProviderInterface {
  use StringTranslationTrait;

  /**
   * The Domain negotiator.
   *
   * @var \Drupal\domain\DomainNegotiatorInterface
   */
  protected $negotiator;

  /**
   * Constructs a CurrentDomainContext object.
   *
   * @param \Drupal\domain\DomainNegotiatorInterface $negotiator
   *   The domain negotiator.
   */
  public function __construct(DomainNegotiatorInterface $negotiator) {
    $this->negotiator = $negotiator;
  }

  /**
   * {@inheritdoc}
   */
  public function getRuntimeContexts(array $unqualified_context_ids) {
    $context = NULL;

    // Load the current domain.
    $current_domain = $this->negotiator
      ->getActiveDomain();

    // Set the context, if we have a domain.
    if (!empty($current_domain) && !empty($current_domain
      ->id())) {
      $context = EntityContext::fromEntity($current_domain, $this
        ->t('Active domain'));

      // Allow caching.
      $cacheability = new CacheableMetadata();
      $cacheability
        ->setCacheContexts([
        'url.site',
      ]);
      $context
        ->addCacheableDependency($cacheability);
    }

    // Prepare the result.
    $result = [
      'domain' => $context,
    ];
    return $result;
  }

  /**
   * {@inheritdoc}
   */
  public function getAvailableContexts() {

    // See https://www.drupal.org/project/domain/issues/3201514
    if ($this->negotiator
      ->getActiveDomain()) {
      return $this
        ->getRuntimeContexts([]);
    }
    return [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CurrentDomainContext::$negotiator protected property The Domain negotiator.
CurrentDomainContext::getAvailableContexts public function Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface::getAvailableContexts
CurrentDomainContext::getRuntimeContexts public function Gets runtime context values for the given context IDs. Overrides ContextProviderInterface::getRuntimeContexts
CurrentDomainContext::__construct public function Constructs a CurrentDomainContext object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.