You are here

public function OrExpression::evaluate in Rules 8.3

Returns the final result after executing the conditions.

Overrides ConditionExpressionContainer::evaluate

File

src/Plugin/RulesExpression/OrExpression.php, line 21

Class

OrExpression
Evaluates a group of conditions with a logical OR.

Namespace

Drupal\rules\Plugin\RulesExpression

Code

public function evaluate(ExecutionStateInterface $state) {

  // Use the iterator to ensure the conditions are sorted.
  foreach ($this as $condition) {

    /** @var \Drupal\rules\Engine\ExpressionInterface $condition */
    if ($condition
      ->executeWithState($state)) {
      $this->rulesDebugLogger
        ->info('%label evaluated to %result.', [
        '%label' => $this
          ->getLabel(),
        '%result' => 'TRUE',
      ]);
      return TRUE;
    }
  }
  $this->rulesDebugLogger
    ->info('%label evaluated to %result.', [
    '%label' => $this
      ->getLabel(),
    '%result' => 'FALSE',
  ]);

  // An empty OR should return TRUE. Otherwise, if all conditions evaluate
  // to FALSE we return FALSE.
  return empty($this->conditions);
}