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