DomainAccessCheck.php in Domain Access 8
File
domain/src/Access/DomainAccessCheck.php
View source
<?php
namespace Drupal\domain\Access;
use Drupal\Core\Access\AccessCheckInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Path\PathMatcherInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\domain\DomainNegotiatorInterface;
use Symfony\Component\Routing\Route;
class DomainAccessCheck implements AccessCheckInterface {
protected $domainNegotiator;
protected $configFactory;
protected $pathMatcher;
public function __construct(DomainNegotiatorInterface $negotiator, ConfigFactoryInterface $config_factory, PathMatcherInterface $path_matcher) {
$this->domainNegotiator = $negotiator;
$this->configFactory = $config_factory;
$this->pathMatcher = $path_matcher;
}
public function applies(Route $route) {
return $this
->checkPath($route
->getPath());
}
public function checkPath($path) {
$allowed_paths = $this->configFactory
->get('domain.settings')
->get('login_paths');
return !$this->pathMatcher
->matchPath($path, $allowed_paths);
}
public function access(AccountInterface $account) {
$domain = $this->domainNegotiator
->getActiveDomain();
if (empty($domain)) {
return AccessResult::allowed()
->addCacheTags([
'url.site',
]);
}
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',
]);
}
}
}
Classes
Name |
Description |
DomainAccessCheck |
Provides a global access check to ensure inactive domains are restricted. |