You are here

protected function ContextHandlerTrait::addProvidedContext in Rules 8.3

Adds provided context values from the plugin to the execution state.

Parameters

\Drupal\Core\Plugin\ContextAwarePluginInterface $plugin: The context aware plugin of which to add provided context.

\Drupal\rules\Context\ExecutionStateInterface $state: The Rules state where the context variables are added.

2 calls to ContextHandlerTrait::addProvidedContext()
ActionExpression::executeWithState in src/Plugin/RulesExpression/ActionExpression.php
Execute the expression with a given Rules state.
ConditionExpression::executeWithState in src/Plugin/RulesExpression/ConditionExpression.php
Execute the expression with a given Rules state.

File

src/Context/ContextHandlerTrait.php, line 205

Class

ContextHandlerTrait
Provides methods for handling context based on the plugin configuration.

Namespace

Drupal\rules\Context

Code

protected function addProvidedContext(CoreContextAwarePluginInterface $plugin, ExecutionStateInterface $state) {

  // If the plugin does not support providing context, there is nothing to do.
  if (!$plugin instanceof ContextProviderInterface) {
    return;
  }
  $provides = $plugin
    ->getProvidedContextDefinitions();
  foreach ($provides as $name => $provided_definition) {

    // Avoid name collisions in the rules state: provided variables can be
    // renamed.
    if (isset($this->configuration['provides_mapping'][$name])) {
      $state
        ->setVariableData($this->configuration['provides_mapping'][$name], $plugin
        ->getProvidedContext($name)
        ->getContextData());
    }
    else {
      $state
        ->setVariableData($name, $plugin
        ->getProvidedContext($name)
        ->getContextData());
    }
  }
}