Unverified Commit eb596f29 authored by larowlan's avatar larowlan

Issue #2894422 by dpagini: AccessResult::forbiddenIf reason

parent 3b3daa35
......@@ -87,13 +87,16 @@ public static function allowedIf($condition) {
*
* @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();
}
/**
......
......@@ -128,6 +128,9 @@ public function testAccessForbiddenReason() {
$reason = $this->getRandomGenerator()->string();
$b = AccessResult::forbidden($reason);
$verify($b, $reason);
$b = AccessResult::forbiddenIf(TRUE, $reason);
$verify($b, $reason);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment