class CurrentPathContext in Rules 8.3
Makes the current path available as a context variable.
Hierarchy
- class \Drupal\rules\ContextProvider\CurrentPathContext implements ContextProviderInterface uses StringTranslationTrait
Expanded class hierarchy of CurrentPathContext
1 string reference to 'CurrentPathContext'
1 service uses CurrentPathContext
File
- src/
ContextProvider/ CurrentPathContext.php, line 16
Namespace
Drupal\rules\ContextProviderView source
class CurrentPathContext implements ContextProviderInterface {
use StringTranslationTrait;
/**
* The current path service.
*
* @var \Drupal\Core\Path\CurrentPathStack
*/
protected $currentPathStack;
/**
* Constructs a new CurrentPathContext.
*
* @param \Drupal\Core\Path\CurrentPathStack $current_path_stack
* The current path stack service.
*/
public function __construct(CurrentPathStack $current_path_stack) {
$this->currentPathStack = $current_path_stack;
}
/**
* {@inheritdoc}
*/
public function getRuntimeContexts(array $unqualified_context_ids) {
$values = [
'path' => $this->currentPathStack
->getPath(),
'url' => Url::fromRoute('<current>', [], [
'absolute' => TRUE,
])
->toString(),
];
$context_definition = new ContextDefinition('current_path', $this
->t('Current path'));
$context = new Context($context_definition, $values);
$cacheability = new CacheableMetadata();
$cacheability
->setCacheContexts([
'url.path',
]);
$context
->addCacheableDependency($cacheability);
$result = [
'current_path' => $context,
];
return $result;
}
/**
* {@inheritdoc}
*/
public function getAvailableContexts() {
return $this
->getRuntimeContexts([]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurrentPathContext:: |
protected | property | The current path service. | |
CurrentPathContext:: |
public | function |
Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface:: |
|
CurrentPathContext:: |
public | function |
Gets runtime context values for the given context IDs. Overrides ContextProviderInterface:: |
|
CurrentPathContext:: |
public | function | Constructs a new CurrentPathContext. | |
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. |