Skip to content
Snippets Groups Projects
Select Git revision
  • 38fdf67298841a59a775ac6dc09383a56130acda
  • 11.x default protected
  • 11.2.x protected
  • 10.6.x protected
  • 10.5.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

EntityInterface.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ConditionAccessResolverTrait.php 1.36 KiB
    <?php
    
    namespace Drupal\Core\Condition;
    
    use Drupal\Component\Plugin\Exception\ContextException;
    
    /**
     * Resolves a set of conditions.
     */
    trait ConditionAccessResolverTrait {
    
      /**
       * Resolves the given conditions based on the condition logic ('and'/'or').
       *
       * @param \Drupal\Core\Condition\ConditionInterface[] $conditions
       *   A set of conditions.
       * @param string $condition_logic
       *   The logic used to compute access, either 'and' or 'or'.
       *
       * @return bool
       *   Whether these conditions grant or deny access.
       */
      protected function resolveConditions($conditions, $condition_logic) {
        foreach ($conditions as $condition) {
          try {
            $pass = $condition->execute();
          }
          catch (ContextException $e) {
            // If a condition is missing context and is not negated, consider that a
            // fail.
            $pass = $condition->isNegated();
          }
    
          // If a condition fails and all conditions were needed, deny access.
          if (!$pass && $condition_logic == 'and') {
            return FALSE;
          }
          // If a condition passes and only one condition was needed, grant access.
          elseif ($pass && $condition_logic == 'or') {
            return TRUE;
          }
        }
    
        // Return TRUE if logic was 'and', meaning all rules passed.
        // Return FALSE if logic was 'or', meaning no rule passed.
        return $condition_logic == 'and';
      }
    
    }