public function DomainAliasAccessControlHandler::checkAccess in Domain Access 8
Performs access checks.
This method is supposed to be overwritten by extending classes that do their own custom access checking.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.
string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.
\Drupal\Core\Session\AccountInterface $account: The user for which to check access.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
Overrides DomainAccessControlHandler::checkAccess
File
- domain_alias/
src/ DomainAliasAccessControlHandler.php, line 18
Class
- DomainAliasAccessControlHandler
- Defines the access controller for the domain alias entity type.
Namespace
Drupal\domain_aliasCode
public function checkAccess(EntityInterface $entity, $operation, AccountInterface $account = NULL) {
$account = $this
->prepareUser($account);
// Check the global permission.
if ($account
->hasPermission('administer domain aliases')) {
return AccessResult::allowed();
}
// For other actions we allow admin if they can administer the parent
// domains.
$domain = $entity
->getDomain();
// If this account can administer the domain, allow access to actions based
// on permission.
if (!empty($domain) && $this
->isDomainAdmin($domain, $account)) {
if ($operation == 'view' && $account
->hasPermission('view domain aliases')) {
return AccessResult::allowed();
}
if ($operation == 'create' && $account
->hasPermission('create domain aliases')) {
return AccessResult::allowed();
}
if ($operation == 'update' && $account
->hasPermission('edit domain aliases')) {
return AccessResult::allowed();
}
if ($operation == 'delete' && $account
->hasPermission('delete domain aliases')) {
return AccessResult::allowed();
}
}
return AccessResult::forbidden();
}