/Drupal 8

public function AccessResult::andIf

public AccessResult::andIf(AccessResultInterface $other)

Combine this access result with another using AND.

When AND-ing 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:

  |A N F
A |A N F
N |N N F
F |F F F


\Drupal\Core\Access\AccessResultInterface $other: The other access result to AND this one with.

Return value


Overrides AccessResultInterface::andIf


core/lib/Drupal/Core/Access/AccessResult.php, line 329


Value object for passing an access result with cacheability metadata.




public function andIf(AccessResultInterface $other) {
  // The other access result's cacheability metadata is merged if $merge_other
  // gets set to TRUE. It gets set to TRUE in one case: if the other access
  // result is used.
  $merge_other = FALSE;
  if ($this->isForbidden() || $other->isForbidden()) {
    $result = static::forbidden();
    if (!$this->isForbidden()) {
      $merge_other = TRUE;
  elseif ($this->isAllowed() && $other->isAllowed()) {
    $result = static::allowed();
    $merge_other = TRUE;
  else {
    $result = static::neutral();
    if (!$this->isNeutral()) {
      $merge_other = TRUE;
  if ($merge_other) {
    // If this access result is not cacheable, then an AND with another access
    // result must also not be cacheable, except if the other access result
    // has isForbidden() === TRUE. isForbidden() access results are contagious
    // in that they propagate regardless of the other value.
    if ($this->getCacheMaxAge() === 0 && !$result->isForbidden()) {
  return $result;

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.