You are here

public function DomainAccessViewsAccess::access in Domain Access 8

File

domain_access/src/Access/DomainAccessViewsAccess.php, line 72

Class

DomainAccessViewsAccess
Class DomainAccessViewsAccess.

Namespace

Drupal\domain_access\Access

Code

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();
}