diff --git a/core/core.services.yml b/core/core.services.yml index eaa0607..f2551f3 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -609,7 +609,7 @@ services: arguments: ['@state', '@current_user'] maintenance_mode_subscriber: class: Drupal\Core\EventSubscriber\MaintenanceModeSubscriber - arguments: ['@site_status_negotiator', '@string_translation', '@url_generator', '@current_user'] + arguments: ['@site_status_negotiator', '@config.factory', '@string_translation', '@url_generator', '@current_user'] tags: - { name: event_subscriber } path_subscriber: diff --git a/core/lib/Drupal/Core/Controller/ExceptionController.php b/core/lib/Drupal/Core/Controller/ExceptionController.php index 7183019..320cb06 100644 --- a/core/lib/Drupal/Core/Controller/ExceptionController.php +++ b/core/lib/Drupal/Core/Controller/ExceptionController.php @@ -18,7 +18,6 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\HttpKernelInterface; use Drupal\Component\Utility\String; -use Drupal\Component\Utility\Xss; use Symfony\Component\Debug\Exception\FlattenException; use Drupal\Core\ContentNegotiation; use Drupal\Core\Utility\Error; @@ -325,29 +324,6 @@ public function on500Html(FlattenException $exception, Request $request) { } /** - * Deliver the 503 page if the site is in maintenance mode. - * - * @param \Symfony\Component\Debug\Exception\FlattenException $exception - * The flattened exception. - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object that triggered this exception. - * - * @return \Symfony\Component\HttpFoundation\Response - * A response object. - */ - public function on503Html(FlattenException $exception, Request $request) { - $maintenance_message = $this->container->get('config.factory')->get('system.maintenance')->get('message'); - $site_name = $this->container->get('config.factory')->get('system.site')->get('name'); - - $content = Xss::filterAdmin(String::format($maintenance_message, array('@site' => $site_name))); - $output = DefaultHtmlPageRenderer::renderPage($content, $this->t('Site under maintenance')); - $response = new Response($output); - $response->setStatusCode(503, 'Service Unavailable'); - - return $response; - } - - /** * Processes an AccessDenied exception that occurred on a JSON request. * * @param \Symfony\Component\Debug\Exception\FlattenException $exception diff --git a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php index f06dfe6..2c057db 100644 --- a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php @@ -7,6 +7,10 @@ namespace Drupal\Core\EventSubscriber; +use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Xss; +use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Page\DefaultHtmlPageRenderer; use Drupal\Core\Routing\RouteMatch; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Session\AccountInterface; @@ -16,8 +20,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; -use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -42,6 +44,13 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface { protected $account; /** + * The config factory. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $config; + + /** * The url generator. * * @var \Drupal\Core\Routing\UrlGeneratorInterface @@ -53,6 +62,8 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface { * * @param \Drupal\Core\Site\StatusNegotiatorInterface $status_negotiator * The site status negotiator. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory. * @param \Drupal\Core\StringTranslation\TranslationInterface $translation * The string translation. * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator @@ -60,8 +71,9 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface { * @param \Drupal\Core\Session\AccountInterface $account * The current user. */ - public function __construct(StatusNegotiatorInterface $status_negotiator, TranslationInterface $translation, UrlGeneratorInterface $url_generator, AccountInterface $account) { + public function __construct(StatusNegotiatorInterface $status_negotiator, ConfigFactoryInterface $config_factory, TranslationInterface $translation, UrlGeneratorInterface $url_generator, AccountInterface $account) { $this->statusNegotiator = $status_negotiator; + $this->config = $config_factory; $this->stringTranslation = $translation; $this->urlGenerator = $url_generator; $this->account = $account; @@ -75,11 +87,18 @@ public function __construct(StatusNegotiatorInterface $status_negotiator, Transl */ public function onKernelRequestMaintenance(GetResponseEvent $event) { $route_match = RouteMatch::createFromRequest($event->getRequest()); - if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST && $this->statusNegotiator->getStatus($route_match) != StatusNegotiatorInterface::SITE_ONLINE) { + if ($this->statusNegotiator->getStatus($route_match) != StatusNegotiatorInterface::SITE_ONLINE) { if (!$this->statusNegotiator->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. - throw new ServiceUnavailableHttpException(); + drupal_maintenance_theme(); + $content = Xss::filterAdmin(String::format($this->config->get('system.maintenance')->get('message'), array( + '@site' => $this->config->get('system.site')->get('name'), + ))); + $content = DefaultHtmlPageRenderer::renderPage($content, $this->t('Site under maintenance')); + $response = new Response('Service unavailable', 503); + $response->setContent($content); + $event->setResponse($response); } else { // Display a message if the logged in user has access to the site in diff --git a/core/modules/user/user.routing.yml b/core/modules/user/user.routing.yml index 7e563f1..0a7b842 100644 --- a/core/modules/user/user.routing.yml +++ b/core/modules/user/user.routing.yml @@ -189,3 +189,5 @@ user.reset: operation: NULL requirements: _access: 'TRUE' + options: + _maintenance_access: TRUE