Mercurial > hg > cmmr2012-drupal-site
diff core/modules/block_content/src/Access/RefinableDependentAccessTrait.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/block_content/src/Access/RefinableDependentAccessTrait.php Thu Feb 28 13:11:55 2019 +0000 @@ -0,0 +1,52 @@ +<?php + +namespace Drupal\block_content\Access; + +use Drupal\Core\Access\AccessibleInterface; + +/** + * Trait for \Drupal\block_content\Access\RefinableDependentAccessInterface. + * + * @internal + */ +trait RefinableDependentAccessTrait { + + /** + * The access dependency. + * + * @var \Drupal\Core\Access\AccessibleInterface + */ + protected $accessDependency; + + /** + * {@inheritdoc} + */ + public function setAccessDependency(AccessibleInterface $access_dependency) { + $this->accessDependency = $access_dependency; + return $this; + } + + /** + * {@inheritdoc} + */ + public function getAccessDependency() { + return $this->accessDependency; + } + + /** + * {@inheritdoc} + */ + public function addAccessDependency(AccessibleInterface $access_dependency) { + if (empty($this->accessDependency)) { + $this->accessDependency = $access_dependency; + return $this; + } + if (!$this->accessDependency instanceof AccessGroupAnd) { + $accessGroup = new AccessGroupAnd(); + $this->accessDependency = $accessGroup->addDependency($this->accessDependency); + } + $this->accessDependency->addDependency($access_dependency); + return $this; + } + +}