diff --git a/core/lib/Drupal/Core/Access/AccessResult.php b/core/lib/Drupal/Core/Access/AccessResult.php index 069194e..143361e 100644 --- a/core/lib/Drupal/Core/Access/AccessResult.php +++ b/core/lib/Drupal/Core/Access/AccessResult.php @@ -2,7 +2,6 @@ namespace Drupal\Core\Access; -use Drupal\Core\Access\AccessResultReasonInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Cache\RefinableCacheableDependencyInterface; @@ -327,9 +326,17 @@ public function orIf(AccessResultInterface $other) { } } else { - $result = static::neutral($other->getReason()); + $result = static::neutral(); if (!$this->isNeutral() || ($this->getCacheMaxAge() === 0 && $other->isNeutral()) || ($this->getCacheMaxAge() !== 0 && $other instanceof CacheableDependencyInterface && $other->getCacheMaxAge() !== 0)) { $merge_other = TRUE; + if ($other instanceof AccessResultReasonInterface) { + $result->setReason($other->getReason()); + } + } + else { + if ($this instanceof AccessResultReasonInterface) { + $result->setReason($this->getReason()); + } } } $result->inheritCacheability($this); @@ -366,9 +373,17 @@ public function andIf(AccessResultInterface $other) { $merge_other = TRUE; } else { - $result = static::neutral($other->getReason()); + $result = static::neutral(); if (!$this->isNeutral()) { $merge_other = TRUE; + if ($other instanceof AccessResultReasonInterface) { + $result->setReason($other->getReason()); + } + } + else { + if ($this instanceof AccessResultReasonInterface) { + $result->setReason($this->getReason()); + } } } $result->inheritCacheability($this);