Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

AccessGroupAnd.php

Namespace

Drupal\block_content\Access

File

core/modules/block_content/src/Access/AccessGroupAnd.php

View source
<?php

namespace Drupal\block_content\Access;

use Drupal\Core\Access\AccessibleInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Session\AccountInterface;

/**
 * An access group where all the dependencies must be allowed.
 *
 * @internal
 */
class AccessGroupAnd implements AccessibleInterface {
    
    /**
     * The access dependencies.
     *
     * @var \Drupal\Core\Access\AccessibleInterface[]
     */
    protected $dependencies = [];
    
    /**
     * {@inheritdoc}
     */
    public function addDependency(AccessibleInterface $dependency) {
        $this->dependencies[] = $dependency;
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function access($operation, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
        $access_result = AccessResult::neutral();
        foreach (array_slice($this->dependencies, 1) as $dependency) {
            $access_result = $access_result->andIf($dependency->access($operation, $account, TRUE));
        }
        return $return_as_object ? $access_result : $access_result->isAllowed();
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDependencies() {
        return $this->dependencies;
    }

}

Classes

Title Deprecated Summary
AccessGroupAnd An access group where all the dependencies must be allowed.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal