You are here

public function ExecutionState::getVariable in Rules 8.3

Gets a variable.

Parameters

string $name: The name of the variable to return.

Return value

\Drupal\Core\TypedData\TypedDataInterface The variable wrapped as typed data.

Throws

\Drupal\rules\Exception\EvaluationException Throws an EvaluationException if the variable does not exist in the state.

Overrides ExecutionStateInterface::getVariable

1 call to ExecutionState::getVariable()
ExecutionState::fetchDataByPropertyPath in src/Context/ExecutionState.php
Returns a value as specified in the selector.

File

src/Context/ExecutionState.php, line 100

Class

ExecutionState
The rules execution state.

Namespace

Drupal\rules\Context

Code

public function getVariable($name) {
  if (!$this
    ->hasVariable($name)) {

    // @todo This crashes site in certain circumstances - for example if
    // you're reacting on a "Drupal is initializing" event ... Need to handle
    // a problem here gracefully - maybe disable the rule that caused the
    // problem?
    throw new EvaluationException("Unable to get variable '{$name}'; it is not defined.");
  }
  return $this->variables[$name];
}