entityTypeManager = $entity_type_manager; $this->domainStorage = $this->entityTypeManager->getStorage('domain'); $this->userStorage = $this->entityTypeManager->getStorage('user'); $this->manager = $manager; } /** * {@inheritdoc} */ public function access(Route $route, AccountInterface $account, $arg_0 = NULL) { // Permissions are stored on the route defaults. $permission = $route->getDefault('domain_permission'); $allPermission = $route->getDefault('domain_all_permission'); // Users with this permission can see any domain content lists, and it is // required to view all affiliates. if ($account->hasPermission($allPermission)) { return AccessResult::allowed(); } // Load the domain from the passed argument. In testing, this passed NULL // in some instances. if (!is_null($arg_0)) { $domain = $this->domainStorage->load($arg_0); } // Domain found, check user permissions. if (!empty($domain)) { if ($this->manager->hasDomainPermissions($account, $domain, [$permission])) { return AccessResult::allowed(); } } return AccessResult::forbidden(); } /** * {@inheritdoc} */ public function applies(Route $route) { return $route->hasRequirement($this->requirementsKey); } }