X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FAccess%2FAccessResult.php;h=3abbf331015bf4f4a03d8d5b6f8bfe0efd506481;hb=refs%2Fheads%2Fd864;hp=1cd6b8bacdc7f78562a8809df124aadb2c8b8bcd;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/lib/Drupal/Core/Access/AccessResult.php b/web/core/lib/Drupal/Core/Access/AccessResult.php index 1cd6b8bac..3abbf3310 100644 --- a/web/core/lib/Drupal/Core/Access/AccessResult.php +++ b/web/core/lib/Drupal/Core/Access/AccessResult.php @@ -39,7 +39,7 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable * isNeutral() will be TRUE. */ public static function neutral($reason = NULL) { - assert('is_string($reason) || is_null($reason)'); + assert(is_string($reason) || is_null($reason)); return new AccessResultNeutral($reason); } @@ -64,7 +64,7 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable * isForbidden() will be TRUE. */ public static function forbidden($reason = NULL) { - assert('is_string($reason) || is_null($reason)'); + assert(is_string($reason) || is_null($reason)); return new AccessResultForbidden($reason); } @@ -87,13 +87,16 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable * * @param bool $condition * The condition to evaluate. + * @param string|null $reason + * (optional) The reason why access is forbidden. Intended for developers, + * hence not translatable * * @return \Drupal\Core\Access\AccessResult * If $condition is TRUE, isForbidden() will be TRUE, otherwise isNeutral() * will be TRUE. */ - public static function forbiddenIf($condition) { - return $condition ? static::forbidden() : static::neutral(); + public static function forbiddenIf($condition, $reason = NULL) { + return $condition ? static::forbidden($reason) : static::neutral(); } /** @@ -333,10 +336,10 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable $merge_other = TRUE; } - if ($this->isForbidden() && $this instanceof AccessResultReasonInterface) { + if ($this->isForbidden() && $this instanceof AccessResultReasonInterface && !is_null($this->getReason())) { $result->setReason($this->getReason()); } - elseif ($other->isForbidden() && $other instanceof AccessResultReasonInterface) { + elseif ($other->isForbidden() && $other instanceof AccessResultReasonInterface && !is_null($other->getReason())) { $result->setReason($other->getReason()); } } @@ -350,14 +353,13 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable $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()); - } + + if ($this instanceof AccessResultReasonInterface && !is_null($this->getReason())) { + $result->setReason($this->getReason()); + } + elseif ($other instanceof AccessResultReasonInterface && !is_null($other->getReason())) { + $result->setReason($other->getReason()); } } $result->inheritCacheability($this); @@ -424,9 +426,9 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable /** * Inherits the cacheability of the other access result, if any. * - * inheritCacheability() differs from addCacheableDependency() in how it - * handles max-age, because it is designed to inherit the cacheability of the - * second operand in the andIf() and orIf() operations. There, the situation + * This method differs from addCacheableDependency() in how it handles + * max-age, because it is designed to inherit the cacheability of the second + * operand in the andIf() and orIf() operations. There, the situation * "allowed, max-age=0 OR allowed, max-age=1000" needs to yield max-age 1000 * as the end result. *