You are here

public function ExecutionState::hasVariable in Rules 8.3

Checks if a variable exists by name in the execution state.

Parameters

string $name: The variable name.

Return value

bool TRUE if the variable exists, FALSE otherwise.

Overrides ExecutionStateInterface::hasVariable

1 call to ExecutionState::hasVariable()
ExecutionState::getVariable in src/Context/ExecutionState.php
Gets a variable.

File

src/Context/ExecutionState.php, line 121

Class

ExecutionState
The rules execution state.

Namespace

Drupal\rules\Context

Code

public function hasVariable($name) {
  if (!array_key_exists($name, $this->variables)) {

    // If there is no such variable, lazy-add global context variables. That
    // way we can save time fetching global context if it is not needed.
    if (!($name[0] === '@' && strpos($name, ':') !== FALSE)) {
      return FALSE;
    }
    $contexts = $this
      ->getGlobalContextRepository()
      ->getRuntimeContexts([
      $name,
    ]);
    if (!array_key_exists($name, $contexts)) {
      return FALSE;
    }
    $this
      ->setVariableData($name, $contexts[$name]
      ->getContextData());
  }
  return TRUE;
}