function MaintenanceModeSubscriber::onMaintenanceModeRequest

Same name in this branch
  1. 10 core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\user\EventSubscriber\MaintenanceModeSubscriber::onMaintenanceModeRequest()
Same name in other branches
  1. 9 core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\user\EventSubscriber\MaintenanceModeSubscriber::onMaintenanceModeRequest()
  2. 9 core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber::onMaintenanceModeRequest()
  3. 11.x core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\user\EventSubscriber\MaintenanceModeSubscriber::onMaintenanceModeRequest()
  4. 11.x core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber::onMaintenanceModeRequest()

Returns response when site is in maintenance mode and user is not exempt.

Parameters

\Symfony\Component\HttpKernel\Event\RequestEvent $event: The event to process.

File

core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php, line 155

Class

MaintenanceModeSubscriber
Maintenance mode subscriber for controller requests.

Namespace

Drupal\Core\EventSubscriber

Code

public function onMaintenanceModeRequest(RequestEvent $event) {
    $request = $event->getRequest();
    if ($request->getRequestFormat() !== 'html') {
        $response = new Response($this->maintenanceMode
            ->getSiteMaintenanceMessage(), 503, [
            'Content-Type' => 'text/plain',
        ]);
        // Calling RequestEvent::setResponse() also stops propagation of event.
        $event->setResponse($response);
        return;
    }
    drupal_maintenance_theme();
    $response = $this->bareHtmlPageRenderer
        ->renderBarePage([
        '#markup' => $this->maintenanceMode
            ->getSiteMaintenanceMessage(),
    ], $this->t('Site under maintenance'), 'maintenance_page');
    $response->setStatusCode(503);
    // Calling RequestEvent::setResponse() also stops propagation of the event.
    $event->setResponse($response);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.