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:
1 2 3 4 5 | |A N F --+----- A |A N F N |N N F F |F F F |
Parameters
\Drupal\Core\Access\AccessResultInterface $other: The other access result to AND this one with.
Return value
static
Overrides AccessResultInterface::andIf
File
- core/lib/Drupal/Core/Access/AccessResult.php, line 334
Class
- AccessResult
- Value object for passing an access result with cacheability metadata.
Namespace
Drupal\Core\Access
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 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()) { 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; } } $result ->inheritCacheability( $this ); if ( $merge_other ) { $result ->inheritCacheability( $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()) { $result ->setCacheMaxAge(0); } } return $result ; } |
Please login to continue.