public function AccessResult::orIf in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Access/AccessResult.php \Drupal\Core\Access\AccessResult::orIf()
- 9 core/lib/Drupal/Core/Access/AccessResult.php \Drupal\Core\Access\AccessResult::orIf()
File
- core/lib/Drupal/Core/Access/AccessResult.php, line 282
Class
- AccessResult
- Value object for passing an access result with cacheability metadata.
Namespace
Drupal\Core\Access
Code
public function orIf(AccessResultInterface $other) {
$merge_other = FALSE;
if ($this
->isForbidden() || $other
->isForbidden()) {
$result = static::forbidden();
if (!$this
->isForbidden() || $this
->getCacheMaxAge() === 0 && $other
->isForbidden()) {
$merge_other = TRUE;
}
if ($this
->isForbidden() && $this instanceof AccessResultReasonInterface && $this
->getReason() !== '') {
$result
->setReason($this
->getReason());
}
elseif ($other
->isForbidden() && $other instanceof AccessResultReasonInterface && $other
->getReason() !== '') {
$result
->setReason($other
->getReason());
}
}
elseif ($this
->isAllowed() || $other
->isAllowed()) {
$result = static::allowed();
if (!$this
->isAllowed() || $this
->getCacheMaxAge() === 0 && $other
->isAllowed() || $this
->getCacheMaxAge() !== 0 && $other instanceof CacheableDependencyInterface && $other
->getCacheMaxAge() !== 0) {
$merge_other = TRUE;
}
}
else {
$result = static::neutral();
if (!$this
->isNeutral() || $this
->getCacheMaxAge() === 0 && $other
->isNeutral() || $this
->getCacheMaxAge() !== 0 && $other instanceof CacheableDependencyInterface && $other
->getCacheMaxAge() !== 0) {
$merge_other = TRUE;
}
if ($this instanceof AccessResultReasonInterface && $this
->getReason() !== '') {
$result
->setReason($this
->getReason());
}
elseif ($other instanceof AccessResultReasonInterface && $other
->getReason() !== '') {
$result
->setReason($other
->getReason());
}
}
$result
->inheritCacheability($this);
if ($merge_other) {
$result
->inheritCacheability($other);
}
return $result;
}