Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function process($value, ExecutionStateInterface $rules_state)
 {
     $data = [];
     $placeholders_by_data = $this->placeholderResovler->scan($value);
     foreach ($placeholders_by_data as $variable_name => $placeholders) {
         // Note that accessing an unavailable variable will throw an evaluation
         // exception. That's exactly what needs to happen. Invalid tokens must
         // be checked when checking integrity.
         $data[$variable_name] = $rules_state->getVariable($variable_name);
     }
     return $this->placeholderResovler->replacePlaceHolders($value, $data);
 }
Ejemplo n.º 2
0
 /**
  * Maps provided context values from the plugin to the Rules state.
  *
  * @param ContextProviderInterface $plugin
  *   The plugin where the context values are extracted.
  * @param \Drupal\rules\Engine\ExecutionStateInterface $state
  *   The Rules state where the context variables are added.
  */
 protected function mapProvidedContext(ContextProviderInterface $plugin, ExecutionStateInterface $state)
 {
     $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());
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function executeWithState(ExecutionStateInterface $state)
 {
     $list_data = $state->fetchDataByPropertyPath($this->configuration['list']);
     // Use a configured list item variable name, otherwise fall back to just
     // 'list_item' as variable name.
     $list_item_name = isset($this->configuration['list_item']) ? $this->configuration['list_item'] : 'list_item';
     foreach ($list_data as $item) {
         $state->setVariableData($list_item_name, $item);
         foreach ($this->actions as $action) {
             $action->executeWithState($state);
         }
     }
     // After the loop the list item is out of scope and cannot be used by any
     // following actions.
     $state->removeVariable($list_item_name);
 }
Ejemplo n.º 4
0
 /**
  * Executes the component with the previously set context.
  *
  * @return mixed[]
  *   The array of provided context values, keyed by context name.
  *
  * @throws \Drupal\rules\Exception\RulesEvaluationException
  *   Thrown if the Rules expression triggers errors during execution.
  */
 public function execute()
 {
     $this->expression->executeWithState($this->state);
     $this->state->autoSave();
     $result = [];
     foreach ($this->providedContext as $name) {
         $result[$name] = $this->state->getVariableValue($name);
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * Adds provided context values from the plugin to the execution state.
  *
  * @param CoreContextAwarePluginInterface $plugin
  *   The context aware plugin of which to add provided context.
  * @param \Drupal\rules\Engine\ExecutionStateInterface $state
  *   The Rules state where the context variables are added.
  */
 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());
         }
     }
 }