class CurrentDomainContext in Domain Access 8
Provides a context handler for the block system.
Hierarchy
- class \Drupal\domain\ContextProvider\CurrentDomainContext implements ContextProviderInterface uses StringTranslationTrait
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
File
- domain/
src/ ContextProvider/ CurrentDomainContext.php, line 16
Namespace
Drupal\domain\ContextProviderView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurrentDomainContext:: |
protected | property | The Domain negotiator. | |
CurrentDomainContext:: |
public | function |
Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface:: |
|
CurrentDomainContext:: |
public | function |
Gets runtime context values for the given context IDs. Overrides ContextProviderInterface:: |
|
CurrentDomainContext:: |
public | function | Constructs a CurrentDomainContext object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |