You are here

protected function ContextHandlerTrait::addProvidedContextDefinitions in Rules 8.3

Adds the definitions of provided context to the execution metadata state.

Parameters

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

\Drupal\rules\Context\ExecutionMetadataStateInterface $metadata_state: The execution metadata state to add variables to.

3 calls to ContextHandlerTrait::addProvidedContextDefinitions()
ActionExpression::prepareExecutionMetadataState in src/Plugin/RulesExpression/ActionExpression.php
Prepares the execution metadata state by adding metadata to it.
ConditionExpression::prepareExecutionMetadataState in src/Plugin/RulesExpression/ConditionExpression.php
Prepares the execution metadata state by adding metadata to it.
ContextHandlerIntegrityTrait::checkContextConfigIntegrity in src/Context/ContextHandlerIntegrityTrait.php
Performs the integrity check.

File

src/Context/ContextHandlerTrait.php, line 231

Class

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

Namespace

Drupal\rules\Context

Code

protected function addProvidedContextDefinitions(CoreContextAwarePluginInterface $plugin, ExecutionMetadataStateInterface $metadata_state) {

  // If the plugin does not support providing context, there is nothing to do.
  if (!$plugin instanceof ContextProviderInterface) {
    return;
  }
  foreach ($plugin
    ->getProvidedContextDefinitions() as $name => $context_definition) {
    if (isset($this->configuration['provides_mapping'][$name])) {

      // Populate the state with the new variable that is provided by this
      // plugin. That is necessary so that the integrity check in subsequent
      // actions knows about the variable and does not throw violations.
      $metadata_state
        ->setDataDefinition($this->configuration['provides_mapping'][$name], $context_definition
        ->getDataDefinition());
    }
    else {
      $metadata_state
        ->setDataDefinition($name, $context_definition
        ->getDataDefinition());
    }
  }
}