class DomainAccessCheck in Domain Access 8
Provides a global access check to ensure inactive domains are restricted.
Hierarchy
- class \Drupal\domain\Access\DomainAccessCheck implements AccessCheckInterface
Expanded class hierarchy of DomainAccessCheck
1 file declares its use of DomainAccessCheck
- DomainSubscriber.php in domain/
src/ EventSubscriber/ DomainSubscriber.php
1 string reference to 'DomainAccessCheck'
- domain.services.yml in domain/
domain.services.yml - domain/domain.services.yml
1 service uses DomainAccessCheck
File
- domain/
src/ Access/ DomainAccessCheck.php, line 16
Namespace
Drupal\domain\AccessView source
class DomainAccessCheck implements AccessCheckInterface {
/**
* The Domain negotiator.
*
* @var \Drupal\domain\DomainNegotiatorInterface
*/
protected $domainNegotiator;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The path matcher service.
*
* @var \Drupal\Core\Path\PathMatcherInterface
*/
protected $pathMatcher;
/**
* Constructs the object.
*
* @param \Drupal\domain\DomainNegotiatorInterface $negotiator
* The domain negotiation service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
* The path matcher service.
*/
public function __construct(DomainNegotiatorInterface $negotiator, ConfigFactoryInterface $config_factory, PathMatcherInterface $path_matcher) {
$this->domainNegotiator = $negotiator;
$this->configFactory = $config_factory;
$this->pathMatcher = $path_matcher;
}
/**
* {@inheritdoc}
*/
public function applies(Route $route) {
return $this
->checkPath($route
->getPath());
}
/**
* {@inheritdoc}
*/
public function checkPath($path) {
$allowed_paths = $this->configFactory
->get('domain.settings')
->get('login_paths');
return !$this->pathMatcher
->matchPath($path, $allowed_paths);
}
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
$domain = $this->domainNegotiator
->getActiveDomain();
// Is the domain allowed?
// No domain, let it pass.
if (empty($domain)) {
return AccessResult::allowed()
->addCacheTags([
'url.site',
]);
}
// Active domain, let it pass.
if ($domain
->status()) {
return AccessResult::allowed()
->addCacheTags([
'url.site',
]);
}
else {
$permissions = [
'administer domains',
'access inactive domains',
];
$operator = 'OR';
return AccessResult::allowedIfHasPermissions($account, $permissions, $operator)
->addCacheTags([
'url.site',
]);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DomainAccessCheck:: |
protected | property | The config factory. | |
DomainAccessCheck:: |
protected | property | The Domain negotiator. | |
DomainAccessCheck:: |
protected | property | The path matcher service. | |
DomainAccessCheck:: |
public | function | ||
DomainAccessCheck:: |
public | function |
Declares whether the access check applies to a specific route or not. Overrides AccessCheckInterface:: |
|
DomainAccessCheck:: |
public | function | ||
DomainAccessCheck:: |
public | function | Constructs the object. |