diff --git a/core/core.services.yml b/core/core.services.yml index f2551f3..c8f99c3 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -604,12 +604,12 @@ services: tags: - { name: access_check, applies_to: _csrf_token } arguments: ['@csrf_token'] - site_status_negotiator: - class: Drupal\Core\Site\StatusNegotiator + maintenance_mode: + class: Drupal\Core\Site\MaintenanceMode arguments: ['@state', '@current_user'] maintenance_mode_subscriber: class: Drupal\Core\EventSubscriber\MaintenanceModeSubscriber - arguments: ['@site_status_negotiator', '@config.factory', '@string_translation', '@url_generator', '@current_user'] + arguments: ['@maintenance_mode', '@config.factory', '@string_translation', '@url_generator', '@current_user'] tags: - { name: event_subscriber } path_subscriber: diff --git a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php index 2c057db..dc14d07 100644 --- a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php @@ -14,7 +14,7 @@ use Drupal\Core\Routing\RouteMatch; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Site\StatusNegotiatorInterface; +use Drupal\Core\Site\MaintenanceModeInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -30,11 +30,11 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface { use StringTranslationTrait; /** - * The site status negotiator. + * The maintenance mode. * - * @var \Drupal\Core\Site\StatusNegotiatorInterface + * @var \Drupal\Core\Site\MaintenanceModeInterface */ - protected $statusNegotiator; + protected $maintenanceMode; /** * The current account. @@ -60,8 +60,8 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface { /** * Constructs a new MaintenanceModeSubscriber. * - * @param \Drupal\Core\Site\StatusNegotiatorInterface $status_negotiator - * The site status negotiator. + * @param \Drupal\Core\Site\MaintenanceModeInterface $maintenance_mode + * The maintenance mode. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. * @param \Drupal\Core\StringTranslation\TranslationInterface $translation @@ -71,8 +71,8 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface { * @param \Drupal\Core\Session\AccountInterface $account * The current user. */ - public function __construct(StatusNegotiatorInterface $status_negotiator, ConfigFactoryInterface $config_factory, TranslationInterface $translation, UrlGeneratorInterface $url_generator, AccountInterface $account) { - $this->statusNegotiator = $status_negotiator; + public function __construct(MaintenanceModeInterface $maintenance_mode, ConfigFactoryInterface $config_factory, TranslationInterface $translation, UrlGeneratorInterface $url_generator, AccountInterface $account) { + $this->maintenanceMode = $maintenance_mode; $this->config = $config_factory; $this->stringTranslation = $translation; $this->urlGenerator = $url_generator; @@ -87,8 +87,8 @@ public function __construct(StatusNegotiatorInterface $status_negotiator, Config */ public function onKernelRequestMaintenance(GetResponseEvent $event) { $route_match = RouteMatch::createFromRequest($event->getRequest()); - if ($this->statusNegotiator->getStatus($route_match) != StatusNegotiatorInterface::SITE_ONLINE) { - if (!$this->statusNegotiator->exempt($this->account)) { + if ($this->maintenanceMode->applies($route_match)) { + if (!$this->maintenanceMode->exempt($this->account)) { // Deliver the 503 page if the site is in maintenance mode and the // logged in user is not allowed to bypass it. drupal_maintenance_theme(); diff --git a/core/lib/Drupal/Core/Site/MaintenanceMode.php b/core/lib/Drupal/Core/Site/MaintenanceMode.php new file mode 100644 index 0000000..cac817c --- /dev/null +++ b/core/lib/Drupal/Core/Site/MaintenanceMode.php @@ -0,0 +1,60 @@ +state = $state; + } + + /** + * {@inheritdoc} + */ + public function applies(RouteMatchInterface $route_match) { + if (!$this->state->get('system.maintenance_mode')) { + return FALSE; + } + + if ($route = $route_match->getRouteObject()) { + if ($route->getOption('_maintenance_access')) { + return FALSE; + } + } + + return TRUE; + } + + /** + * {@inheritdoc} + */ + public function exempt(AccountInterface $account) { + return $account->hasPermission('access site in maintenance mode'); + } + +} diff --git a/core/lib/Drupal/Core/Site/MaintenanceModeInterface.php b/core/lib/Drupal/Core/Site/MaintenanceModeInterface.php new file mode 100644 index 0000000..064885c --- /dev/null +++ b/core/lib/Drupal/Core/Site/MaintenanceModeInterface.php @@ -0,0 +1,41 @@ +state = $state; - } - - /** - * {@inheritdoc} - */ - public function getStatus(RouteMatchInterface $route_match) { - if (!$this->state->get('system.maintenance_mode')) { - return StatusNegotiatorInterface::SITE_ONLINE; - } - - if ($route = $route_match->getRouteObject()) { - if ($route->getOption('_maintenance_access')) { - return StatusNegotiatorInterface::SITE_ONLINE; - } - } - - return StatusNegotiatorInterface::SITE_OFFLINE; - } - - /** - * {@inheritdoc} - */ - public function exempt(AccountInterface $account) { - return $account->hasPermission('access site in maintenance mode'); - } - -} diff --git a/core/lib/Drupal/Core/Site/StatusNegotiatorInterface.php b/core/lib/Drupal/Core/Site/StatusNegotiatorInterface.php deleted file mode 100644 index 7e72ebe..0000000 --- a/core/lib/Drupal/Core/Site/StatusNegotiatorInterface.php +++ /dev/null @@ -1,61 +0,0 @@ -statusNegotiator = $status_negotiator; + public function __construct(MaintenanceModeInterface $maintenance_mode, AccountInterface $account) { + $this->maintenanceMode = $maintenance_mode; $this->account = $account; } @@ -56,11 +56,10 @@ public function __construct(StatusNegotiatorInterface $status_negotiator, Accoun public function onKernelRequestMaintenance(GetResponseEvent $event) { $request = $event->getRequest(); $route_match = RouteMatch::createFromRequest($request); - $site_status = $this->statusNegotiator->getStatus($route_match); $path = $request->attributes->get('_system_path'); - if ($site_status == StatusNegotiatorInterface::SITE_OFFLINE) { + if ($this->maintenanceMode->applies($route_match)) { // If the site is offline, log out unprivileged users. - if ($this->account->isAuthenticated() && !$this->statusNegotiator->exempt($this->account)) { + if ($this->account->isAuthenticated() && !$this->maintenanceMode->exempt($this->account)) { user_logout(); // Redirect to homepage. $event->setResponse(new RedirectResponse(url('', array('absolute' => TRUE)))); diff --git a/core/modules/user/user.services.yml b/core/modules/user/user.services.yml index 3a3e3a8..a408fcf 100644 --- a/core/modules/user/user.services.yml +++ b/core/modules/user/user.services.yml @@ -38,7 +38,7 @@ services: arguments: ['@database', '@config.factory', '@entity.manager', '@entity.query'] user_maintenance_mode_subscriber: class: Drupal\user\EventSubscriber\MaintenanceModeSubscriber - arguments: ['@site_status_negotiator', '@current_user'] + arguments: ['@maintenance_mode', '@current_user'] tags: - { name: event_subscriber } theme.negotiator.admin_theme: