public function Rule::evaluateConditions in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/Entity/Rule.php \Drupal\rng\Entity\Rule::evaluateConditions()
- 3.x src/Entity/Rule.php \Drupal\rng\Entity\Rule::evaluateConditions()
Evaluates all conditions on the rule.
Parameters
array $context_values: Context to pass to conditions. Keyed by context name.
Return value
bool Whether all conditions evaluate true.
Throws
\Drupal\Component\Plugin\Exception\ContextException If a context value is missing for any condition.
Overrides RuleInterface::evaluateConditions
File
- src/
Entity/ Rule.php, line 120
Class
- Rule
- Defines the event rule entity.
Namespace
Drupal\rng\EntityCode
public function evaluateConditions($context_values = []) {
$success = 0;
$conditions = $this
->getConditions();
// Counts successfully loaded condition plugins:
$count = 0;
foreach ($conditions as $component) {
if (($condition = $component
->createInstance()) !== NULL) {
$count++;
}
$context_definitions = $condition
->getContextDefinitions();
foreach ($context_values as $name => $value) {
if (isset($context_definitions[$name])) {
$condition
->setContextValue($name, $value);
}
}
if ($condition
->evaluate()) {
$success++;
}
else {
// Cancel evaluating remaining conditions.
return FALSE;
}
}
return $success == count($conditions) && $count == count($conditions);
}