public function MaintenanceModeSubscriber::onKernelRequestMaintenanceModeCheck

Response with the maintenance page when the site is offline.

Parameters

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

File

drupal/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php, line 26
Definition of Drupal\Core\EventSubscriber\MaintenanceModeSubscriber.

Class

MaintenanceModeSubscriber
Maintenance mode subscriber for controller requests.

Namespace

Drupal\Core\EventSubscriber

Code

public function onKernelRequestMaintenanceModeCheck(GetResponseEvent $event) {

  // Check if the site is offline.
  $status = _menu_site_is_offline() ? MENU_SITE_OFFLINE : MENU_SITE_ONLINE;

  // Allow other modules to change the site status but not the path because
  // that would not change the global variable. hook_url_inbound_alter() can
  // be used to change the path. Code later will not use the $read_only_path
  // variable.
  $read_only_path = !empty($path) ? $path : $event
    ->getRequest()->attributes
    ->get('system_path');
  drupal_alter('menu_site_status', $status, $read_only_path);

  // Only continue if the site is online.
  if ($status != MENU_SITE_ONLINE) {

    // Deliver the 503 page.
    drupal_maintenance_theme();
    drupal_set_title(t('Site under maintenance'));
    $content = theme('maintenance_page', array(
      'content' => filter_xss_admin(t(config('system.maintenance')
        ->get('message'), array(
        '@site' => config('system.site')
          ->get('name'),
      ))),
    ));
    $response = new Response('Service unavailable', 503);
    $response
      ->setContent($content);
    $event
      ->setResponse($response);
  }
}