class DomainAccessViewsAccess in Domain Access 8
Class DomainAccessViewsAccess.
@package Drupal\domain_access\Access
Hierarchy
- class \Drupal\domain_access\Access\DomainAccessViewsAccess implements AccessCheckInterface
Expanded class hierarchy of DomainAccessViewsAccess
1 string reference to 'DomainAccessViewsAccess'
- domain_access.services.yml in domain_access/
domain_access.services.yml - domain_access/domain_access.services.yml
1 service uses DomainAccessViewsAccess
File
- domain_access/
src/ Access/ DomainAccessViewsAccess.php, line 17
Namespace
Drupal\domain_access\AccessView source
class DomainAccessViewsAccess implements AccessCheckInterface {
/**
* The key used by the routing requirement.
*
* @var string
*/
protected $requirementsKey = '_domain_access_views';
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The Domain storage handler.
*
* @var \Drupal\domain\DomainStorageInterface
*/
protected $domainStorage;
/**
* User storage.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
/**
* The Domain access manager.
*
* @var \Drupal\domain_access\DomainAccessManagerInterface
*/
protected $manager;
/**
* Constructs a DomainToken object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\domain_access\DomainAccessManagerInterface $manager
* The domain access manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, DomainAccessManagerInterface $manager) {
$this->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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DomainAccessViewsAccess:: |
protected | property | The Domain storage handler. | |
DomainAccessViewsAccess:: |
protected | property | The entity type manager. | |
DomainAccessViewsAccess:: |
protected | property | The Domain access manager. | |
DomainAccessViewsAccess:: |
protected | property | The key used by the routing requirement. | |
DomainAccessViewsAccess:: |
protected | property | User storage. | |
DomainAccessViewsAccess:: |
public | function | ||
DomainAccessViewsAccess:: |
public | function |
Declares whether the access check applies to a specific route or not. Overrides AccessCheckInterface:: |
|
DomainAccessViewsAccess:: |
public | function | Constructs a DomainToken object. |