/**
  * Returns the site maintenance page if the site is offline.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  *   The event to process.
  */
 public function onKernelRequestMaintenance(GetResponseEvent $event)
 {
     $route_match = RouteMatch::createFromRequest($event->getRequest());
     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();
             $content = Xss::filterAdmin(String::format($this->config->get('system.maintenance')->get('message'), array('@site' => $this->config->get('system.site')->get('name'))));
             // @todo Break the dependency on DefaultHtmlPageRenderer, see:
             //   https://www.drupal.org/node/2295609
             $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
             // maintenance mode. However, suppress it on the maintenance mode
             // settings page.
             if ($route_match->getRouteName() != 'system.site_maintenance_mode') {
                 if ($this->account->hasPermission('administer site configuration')) {
                     $this->drupalSetMessage($this->t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => $this->urlGenerator->generate('system.site_maintenance_mode'))), 'status', FALSE);
                 } else {
                     $this->drupalSetMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
                 }
             }
         }
     }
 }
 /**
  * Returns the site maintenance page if the site is offline.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  *   The event to process.
  */
 public function onKernelRequestMaintenance(GetResponseEvent $event)
 {
     $route_match = RouteMatch::createFromRequest($event->getRequest());
     if ($this->maintenanceMode->applies($route_match)) {
         // Don't cache maintenance mode pages.
         \Drupal::service('page_cache_kill_switch')->trigger();
         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();
             $content = Xss::filterAdmin(SafeMarkup::format($this->config->get('system.maintenance')->get('message'), array('@site' => $this->config->get('system.site')->get('name'))));
             $output = $this->bareHtmlPageRenderer->renderBarePage(['#markup' => $content], $this->t('Site under maintenance'), 'maintenance_page');
             $response = new Response($output, 503);
             $event->setResponse($response);
         } else {
             // Display a message if the logged in user has access to the site in
             // maintenance mode. However, suppress it on the maintenance mode
             // settings page.
             if ($route_match->getRouteName() != 'system.site_maintenance_mode') {
                 if ($this->account->hasPermission('administer site configuration')) {
                     $this->drupalSetMessage($this->t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => $this->urlGenerator->generate('system.site_maintenance_mode'))), 'status', FALSE);
                 } else {
                     $this->drupalSetMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
                 }
             }
         }
     }
 }
 /**
  * Returns the site maintenance page if the site is offline.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  *   The event to process.
  */
 public function onKernelRequestMaintenance(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $route_match = RouteMatch::createFromRequest($request);
     if ($this->maintenanceMode->applies($route_match)) {
         // Don't cache maintenance mode pages.
         \Drupal::service('page_cache_kill_switch')->trigger();
         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.
             // If the request format is not 'html' then show default maintenance
             // mode page else show a text/plain page with maintenance message.
             if ($request->getRequestFormat() !== 'html') {
                 $response = new Response($this->getSiteMaintenanceMessage(), 503, array('Content-Type' => 'text/plain'));
                 $event->setResponse($response);
                 return;
             }
             drupal_maintenance_theme();
             $response = $this->bareHtmlPageRenderer->renderBarePage(['#markup' => $this->getSiteMaintenanceMessage()], $this->t('Site under maintenance'), 'maintenance_page');
             $response->setStatusCode(503);
             $event->setResponse($response);
         } else {
             // Display a message if the logged in user has access to the site in
             // maintenance mode. However, suppress it on the maintenance mode
             // settings page.
             if ($route_match->getRouteName() != 'system.site_maintenance_mode') {
                 if ($this->account->hasPermission('administer site configuration')) {
                     $this->drupalSetMessage($this->t('Operating in maintenance mode. <a href=":url">Go online.</a>', array(':url' => $this->urlGenerator->generate('system.site_maintenance_mode'))), 'status', FALSE);
                 } else {
                     $this->drupalSetMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
                 }
             }
         }
     }
 }