You are here

public function ConditionGroup::evaluate in Commerce Core 8.2

Evaluates the condition group.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity.

Return value

bool TRUE if the condition group has passed, FALSE otherwise.

File

src/ConditionGroup.php, line 79

Class

ConditionGroup
Represents a condition group.

Namespace

Drupal\commerce

Code

public function evaluate(EntityInterface $entity) : bool {
  if (empty($this->conditions)) {
    return TRUE;
  }
  $boolean = $this->operator == 'AND' ? FALSE : TRUE;
  foreach ($this->conditions as $condition) {
    if ($condition
      ->evaluate($entity) == $boolean) {
      return $boolean;
    }
  }
  return !$boolean;
}