You are here

public function ActionExpression::executeWithState in Rules 8.3

Execute the expression with a given Rules state.

Note that this does not auto-save any changes.

Parameters

\Drupal\rules\Context\ExecutionStateInterface $state: The state with all the execution variables in it.

Return value

null|bool The expression may return a boolean value after execution, this is used by conditions that return their evaluation result.

Throws

\Drupal\rules\Exception\EvaluationException Thrown if the Rules expression triggers errors during execution.

Overrides ExpressionInterface::executeWithState

File

src/Plugin/RulesExpression/ActionExpression.php, line 102

Class

ActionExpression
Provides an executable action expression.

Namespace

Drupal\rules\Plugin\RulesExpression

Code

public function executeWithState(ExecutionStateInterface $state) {
  $this->rulesDebugLogger
    ->info('Evaluating the action %name.', [
    '%name' => $this
      ->getLabel(),
    'element' => $this,
  ]);
  $action = $this->actionManager
    ->createInstance($this->configuration['action_id']);
  $this
    ->prepareContext($action, $state);
  $action
    ->execute();
  $auto_saves = $action
    ->autoSaveContext();
  foreach ($auto_saves as $context_name) {

    // Mark parameter contexts for auto saving in the Rules state.
    $state
      ->saveChangesLater($this->configuration['context_mapping'][$context_name]);
  }

  // Now that the action has been executed it can provide additional
  // context which we will have to pass back in the evaluation state.
  $this
    ->addProvidedContext($action, $state);
}