3 namespace Drupal\Core\Condition;
5 use Drupal\Component\Plugin\Exception\ContextException;
8 * Resolves a set of conditions.
10 trait ConditionAccessResolverTrait {
13 * Resolves the given conditions based on the condition logic ('and'/'or').
15 * @param \Drupal\Core\Condition\ConditionInterface[] $conditions
16 * A set of conditions.
17 * @param string $condition_logic
18 * The logic used to compute access, either 'and' or 'or'.
21 * Whether these conditions grant or deny access.
23 protected function resolveConditions($conditions, $condition_logic) {
24 foreach ($conditions as $condition) {
26 $pass = $condition->execute();
28 catch (ContextException $e) {
29 // If a condition is missing context and is not negated, consider that a
31 $pass = $condition->isNegated();
34 // If a condition fails and all conditions were needed, deny access.
35 if (!$pass && $condition_logic == 'and') {
38 // If a condition passes and only one condition was needed, grant access.
39 elseif ($pass && $condition_logic == 'or') {
44 // Return TRUE if logic was 'and', meaning all rules passed.
45 // Return FALSE if logic was 'or', meaning no rule passed.
46 return $condition_logic == 'and';