You are here

public function RuleExpression::prepareExecutionMetadataState in Rules 8.3

Prepares the execution metadata state by adding metadata to it.

If this expression contains other expressions then the metadata state is set up recursively. If a $until expression is specified then the setup will stop right before that expression to calculate the state at this execution point. This is useful for inspecting the state at a certain point in the expression tree as needed during configuration, for example to do autocompletion of available variables in the state.

The difference to fully preparing the state is that not necessarily all variables are available in the middle of the expression tree, as for example variables being added later are not added yet. Preparing with $until = NULL reflects the execution metadata state at the end of the expression execution.

Parameters

\Drupal\rules\Context\ExecutionMetadataStateInterface $metadata_state: The execution metadata state, prepared until right before this expression.

\Drupal\rules\Engine\ExpressionInterface $until: (optional) The expression at which metadata preparation should be stopped. The preparation of the state will be stopped right before that expression.

bool $apply_assertions: (optional) Whether to apply metadata assertions while preparing the execution metadata state. Defaults to TRUE. Metadata assertions should be only applied if the expression's execution is required for sub-sequent expressions being executed. For example, if a condition is optional as it is part of a logical OR expression, its assertions may not be applied. Defaults to TRUE.

Return value

true|null True if the metadata has been prepared and the $until expression was found in the tree. Null otherwise.

Overrides ExpressionInterface::prepareExecutionMetadataState

File

src/Plugin/RulesExpression/RuleExpression.php, line 252

Class

RuleExpression
Provides a rule, executing actions when conditions are met.

Namespace

Drupal\rules\Plugin\RulesExpression

Code

public function prepareExecutionMetadataState(ExecutionMetadataStateInterface $metadata_state, ExpressionInterface $until = NULL, $apply_assertions = TRUE) {

  // @todo If the rule is nested, we may not pass assertions to following
  // expressions as we do not know whether the rule fires at all. Should we
  // clone the metadata state to ensure modifications stay local?
  $found = $this->conditions
    ->prepareExecutionMetadataState($metadata_state, $until, $apply_assertions);
  if ($found) {
    return TRUE;
  }
  return $this->actions
    ->prepareExecutionMetadataState($metadata_state, $until, $apply_assertions);
}