a2f3d1e6211c5b1f74b08d387a8f143f0ad3fd84
[yaffs-website] / web / core / modules / block_content / src / Access / AccessGroupAnd.php
1 <?php
2
3 namespace Drupal\block_content\Access;
4
5 use Drupal\Core\Access\AccessibleInterface;
6 use Drupal\Core\Access\AccessResult;
7 use Drupal\Core\Session\AccountInterface;
8
9 /**
10  * An access group where all the dependencies must be allowed.
11  *
12  * @internal
13  */
14 class AccessGroupAnd implements AccessibleInterface {
15
16   /**
17    * The access dependencies.
18    *
19    * @var \Drupal\Core\Access\AccessibleInterface[]
20    */
21   protected $dependencies = [];
22
23   /**
24    * {@inheritdoc}
25    */
26   public function addDependency(AccessibleInterface $dependency) {
27     $this->dependencies[] = $dependency;
28     return $this;
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
35     $access_result = AccessResult::neutral();
36     foreach (array_slice($this->dependencies, 1) as $dependency) {
37       $access_result = $access_result->andIf($dependency->access($operation, $account, TRUE));
38     }
39     return $return_as_object ? $access_result : $access_result->isAllowed();
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function getDependencies() {
46     return $this->dependencies;
47   }
48
49 }