AccessResultForbidden
class AccessResultForbidden extends AccessResult implements AccessResultReasonInterface (View source)
Value object indicating a forbidden access result, with cacheability metadata.
Traits
Trait for \Drupal\Core\Cache\RefinableCacheableDependencyInterface.
Trait for \Drupal\Core\Cache\CacheableDependencyInterface.
Properties
| protected string[] | $cacheContexts | Cache contexts. |
from CacheableDependencyTrait |
| protected string[] | $cacheTags | Cache tags. |
from CacheableDependencyTrait |
| protected int | $cacheMaxAge | Cache max-age. |
from CacheableDependencyTrait |
| protected string | $reason | The reason why access is forbidden. For use in error messages. |
Methods
Sets cacheability; useful for value object constructors.
Creates an AccessResultInterface object with isNeutral() === TRUE.
Creates an AccessResultInterface object with isAllowed() === TRUE.
Creates an AccessResultInterface object with isForbidden() === TRUE.
Creates an allowed or neutral access result.
Creates a forbidden or neutral access result.
Creates an allowed access result if the permission is present, neutral otherwise.
Creates an allowed access result if the permissions are present, neutral otherwise.
Checks whether this access result indicates access is explicitly allowed.
Checks whether this access result indicates access is explicitly forbidden.
Checks whether this access result indicates access is not yet determined.
Sets the maximum age for which this access result may be cached.
Convenience method, adds the "user.permissions" cache context.
Inherits the cacheability of the other access result, if any.
Constructs a new AccessResultForbidden instance.
Gets the reason for this access result.
Sets the reason for this access result.
Details
protected $this
setCacheability(CacheableDependencyInterface $cacheability)
Sets cacheability; useful for value object constructors.
getCacheTags()
{@inheritdoc}
getCacheContexts()
{@inheritdoc}
getCacheMaxAge()
{@inheritdoc}
addCacheableDependency($other_object)
{@inheritdoc}
addCacheContexts(array $cache_contexts)
{@inheritdoc}
addCacheTags(array $cache_tags)
{@inheritdoc}
mergeCacheMaxAge($max_age)
{@inheritdoc}
static AccessResultNeutral
neutral(string|null $reason = NULL)
Creates an AccessResultInterface object with isNeutral() === TRUE.
static AccessResultAllowed
allowed()
Creates an AccessResultInterface object with isAllowed() === TRUE.
static AccessResultForbidden
forbidden(string|null $reason = NULL)
Creates an AccessResultInterface object with isForbidden() === TRUE.
static AccessResult
allowedIf(bool $condition)
Creates an allowed or neutral access result.
static AccessResult
forbiddenIf(bool $condition, string|null $reason = NULL)
Creates a forbidden or neutral access result.
static AccessResult
allowedIfHasPermission(AccountInterface $account, string $permission)
Creates an allowed access result if the permission is present, neutral otherwise.
Checks the permission and adds a 'user.permissions' cache context.
static AccessResult
allowedIfHasPermissions(AccountInterface $account, array $permissions, string $conjunction = 'AND')
Creates an allowed access result if the permissions are present, neutral otherwise.
Checks the permission and adds a 'user.permissions' cache contexts.
bool
isAllowed()
Checks whether this access result indicates access is explicitly allowed.
bool
isForbidden()
Checks whether this access result indicates access is explicitly forbidden.
This is a kill switch — both orIf() and andIf() will result in isForbidden() if either results are isForbidden().
bool
isNeutral()
Checks whether this access result indicates access is not yet determined.
$this
resetCacheContexts()
Resets cache contexts (to the empty array).
$this
resetCacheTags()
Resets cache tags (to the empty array).
$this
setCacheMaxAge(int $max_age)
Sets the maximum age for which this access result may be cached.
$this
cachePerPermissions()
Convenience method, adds the "user.permissions" cache context.
$this
cachePerUser()
Convenience method, adds the "user" cache context.
AccessResultInterface
orIf(AccessResultInterface $other)
Combine this access result with another using OR.
When ORing two access results, the result is:
- isForbidden() in either ⇒ isForbidden()
- otherwise if isAllowed() in either ⇒ isAllowed()
- otherwise both must be isNeutral() ⇒ isNeutral()
Truth table:
AccessResultInterface
andIf(AccessResultInterface $other)
Combine this access result with another using AND.
When ANDing two access results, the result is:
- isForbidden() in either ⇒ isForbidden()
- otherwise, if isAllowed() in both ⇒ isAllowed()
- otherwise, one of them is isNeutral() ⇒ isNeutral()
Truth table:
$this
inheritCacheability(AccessResultInterface $other)
Inherits the cacheability of the other access result, if any.
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.
__construct(null|string $reason = NULL)
Constructs a new AccessResultForbidden instance.
string
getReason()
Gets the reason for this access result.
AccessResultInterface
setReason($reason)
Sets the reason for this access result.