You are here

public function DomainAccessContent::access in Domain Access 8

Determine if the current user has access or not.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user who wants to access this view.

Return value

bool Returns whether the user has access to the view.

Overrides AccessPluginBase::access

File

domain_access/src/Plugin/views/access/DomainAccessContent.php, line 113

Class

DomainAccessContent
Access plugin that provides domain-editing access control.

Namespace

Drupal\domain_access\Plugin\views\access

Code

public function access(AccountInterface $account) {

  // Users with this permission can see any domain content lists, and it is
  // required to view all affiliates.
  if ($account
    ->hasPermission($this->allPermission)) {
    return TRUE;
  }

  // The routine below determines what domain (if any) was passed to the View.
  if (isset($this->view->element['#arguments'])) {
    foreach ($this->view->element['#arguments'] as $value) {
      if ($domain = $this->domainStorage
        ->load($value)) {
        break;
      }
    }
  }

  // Domain found, check user permissions.
  if (!empty($domain)) {
    return $this->manager
      ->hasDomainPermissions($account, $domain, [
      $this->permission,
    ]);
  }
  return FALSE;
}