function CurrentPathContext::getRuntimeContexts

Overrides ContextProviderInterface::getRuntimeContexts

1 call to CurrentPathContext::getRuntimeContexts()
CurrentPathContext::getAvailableContexts in src/ContextProvider/CurrentPathContext.php
Gets all available contexts for the purposes of configuration.

File

src/ContextProvider/CurrentPathContext.php, line 39

Class

CurrentPathContext
Makes the current path available as a context variable.

Namespace

Drupal\rules\ContextProvider

Code

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;
}