class SiteContext in Rules 8.3
Sets the current node as a context on node routes.
Modules may add properties to this global context by implementing hook_data_type_info_alter(&$data_types) to modify the $data_types['site'] element.
@todo Need a way to alter the global context contents to set a value for any added site properties.
Hierarchy
- class \Drupal\rules\ContextProvider\SiteContext implements ContextProviderInterface uses StringTranslationTrait
Expanded class hierarchy of SiteContext
1 string reference to 'SiteContext'
1 service uses SiteContext
File
- src/
ContextProvider/ SiteContext.php, line 23
Namespace
Drupal\rules\ContextProviderView source
class SiteContext implements ContextProviderInterface {
use StringTranslationTrait;
/**
* The system.site configuration.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $systemSiteConfig;
/**
* Constructs a new SiteContext.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config.factory service.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->systemSiteConfig = $config_factory
->get('system.site');
}
/**
* {@inheritdoc}
*/
public function getRuntimeContexts(array $unqualified_context_ids) {
$site = [
'url' => Url::fromRoute('<front>', [], [
'absolute' => TRUE,
])
->toString(),
'login-url' => Url::fromRoute('user.page', [], [
'absolute' => TRUE,
])
->toString(),
'name' => $this->systemSiteConfig
->get('name'),
'slogan' => $this->systemSiteConfig
->get('slogan'),
'mail' => $this->systemSiteConfig
->get('mail'),
];
$context_definition = new ContextDefinition('site', $this
->t('Site information'));
$context = new Context($context_definition, $site);
$cacheability = new CacheableMetadata();
$cacheability
->setCacheContexts([
'site',
]);
$context
->addCacheableDependency($cacheability);
$result = [
'site' => $context,
];
return $result;
}
/**
* {@inheritdoc}
*/
public function getAvailableContexts() {
return $this
->getRuntimeContexts([]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SiteContext:: |
protected | property | The system.site configuration. | |
SiteContext:: |
public | function |
Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface:: |
|
SiteContext:: |
public | function |
Gets runtime context values for the given context IDs. Overrides ContextProviderInterface:: |
|
SiteContext:: |
public | function | Constructs a new SiteContext. | |
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. |