public function DomainRouteCheck::access in Domain Access 8
Checks access to a route with a _domain requirement.
Parameters
\Symfony\Component\Routing\Route $route: The route to check against.
\Drupal\Core\Session\AccountInterface $account: The currently logged in account.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
See also
\Drupal\domain\Plugin\views\access\Domain
File
- domain/
src/ Access/ DomainRouteCheck.php, line 68
Class
- DomainRouteCheck
- Determines access to routes based on domains.
Namespace
Drupal\domain\AccessCode
public function access(Route $route, AccountInterface $account) {
// Requirements just allow strings, so this might be a comma separated list.
$string = $route
->getRequirement($this->requirementsKey);
$domain = $this->domainNegotiator
->getActiveDomain();
// Since only one domain can be active per request, we only suport OR logic.
$allowed = array_filter(array_map('trim', explode('+', $string)));
if (!empty($domain) && in_array($domain
->id(), $allowed)) {
return AccessResult::allowed()
->addCacheContexts([
'url.site',
]);
}
// If there is no allowed domain, give other access checks a chance.
return AccessResult::neutral()
->addCacheContexts([
'url.site',
]);
}