98b2a547ccfb977cfb3709c1adda2505f8d90a99
[yaffs-website] / web / core / modules / block_content / src / Access / RefinableDependentAccessTrait.php
1 <?php
2
3 namespace Drupal\block_content\Access;
4
5 use Drupal\Core\Access\AccessibleInterface;
6
7 /**
8  * Trait for \Drupal\block_content\Access\RefinableDependentAccessInterface.
9  *
10  * @internal
11  */
12 trait RefinableDependentAccessTrait {
13
14   /**
15    * The access dependency.
16    *
17    * @var \Drupal\Core\Access\AccessibleInterface
18    */
19   protected $accessDependency;
20
21   /**
22    * {@inheritdoc}
23    */
24   public function setAccessDependency(AccessibleInterface $access_dependency) {
25     $this->accessDependency = $access_dependency;
26     return $this;
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function getAccessDependency() {
33     return $this->accessDependency;
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function addAccessDependency(AccessibleInterface $access_dependency) {
40     if (empty($this->accessDependency)) {
41       $this->accessDependency = $access_dependency;
42       return $this;
43     }
44     if (!$this->accessDependency instanceof AccessGroupAnd) {
45       $accessGroup = new AccessGroupAnd();
46       $this->accessDependency = $accessGroup->addDependency($this->accessDependency);
47     }
48     $this->accessDependency->addDependency($access_dependency);
49     return $this;
50   }
51
52 }