function ContextHandlerTrait::processData

Process data context on the plugin, usually before it gets executed.

Parameters

\Drupal\Core\Plugin\ContextAwarePluginInterface $plugin: The plugin to process the context data on.

\Drupal\rules\Context\ExecutionStateInterface $rules_state: The current Rules execution state with context variables.

1 call to ContextHandlerTrait::processData()
ContextHandlerTrait::prepareContext in src/Context/ContextHandlerTrait.php
Prepares plugin context based upon the set context configuration.

File

src/Context/ContextHandlerTrait.php, line 286

Class

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

Namespace

Drupal\rules\Context

Code

protected function processData(CoreContextAwarePluginInterface $plugin, ExecutionStateInterface $rules_state) {
    if (isset($this->configuration['context_processors'])) {
        foreach ($this->configuration['context_processors'] as $context_name => $processors) {
            $definition = $plugin->getContextDefinition($context_name);
            $value = $plugin->getContextValue($context_name);
            if ($definition->isMultiple()) {
                foreach ($value as &$current) {
                    $current = $this->processValue($current, $processors, $rules_state);
                }
            }
            else {
                $value = $this->processValue($value, $processors, $rules_state);
            }
            $plugin->setContextValue($context_name, $value);
        }
    }
}