function MaintenanceModeSubscriber::onKernelRequestMaintenance
Same name in other branches
- 9 core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\user\EventSubscriber\MaintenanceModeSubscriber::onKernelRequestMaintenance()
- 9 core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber::onKernelRequestMaintenance()
- 8.9.x core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\user\EventSubscriber\MaintenanceModeSubscriber::onKernelRequestMaintenance()
- 8.9.x core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber::onKernelRequestMaintenance()
- 10 core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber::onKernelRequestMaintenance()
Returns the site maintenance page if the site is offline.
Parameters
\Symfony\Component\HttpKernel\Event\RequestEvent $event: The event to process.
File
-
core/
lib/ Drupal/ Core/ EventSubscriber/ MaintenanceModeSubscriber.php, line 114
Class
- MaintenanceModeSubscriber
- Maintenance mode subscriber for controller requests.
Namespace
Drupal\Core\EventSubscriberCode
public function onKernelRequestMaintenance(RequestEvent $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)) {
// When the account is not exempt, other subscribers handle request.
$this->eventDispatcher
->dispatch($event, MaintenanceModeEvents::MAINTENANCE_MODE_REQUEST);
}
else {
// Display a message if the logged-in user has access to the site in
// maintenance mode. Don't show maintenance message:
// - on AJAX requests.
// - on Iframe uploads.
// - on the maintenance mode settings page.
if ($route_match->getRouteName() != 'system.site_maintenance_mode') {
$show_message = $route_match->getRouteName() != 'system.site_maintenance_mode' && !$event->getRequest()
->isXmlHttpRequest() && $event->getRequest()
->get('ajax_iframe_upload', FALSE) === FALSE;
if ($show_message) {
if ($this->account
->hasPermission('administer site configuration')) {
$this->messenger
->addMessage($this->t('Operating in maintenance mode. <a href=":url">Go online.</a>', [
':url' => $this->urlGenerator
->generate('system.site_maintenance_mode'),
]), 'status', FALSE);
}
else {
$this->messenger
->addMessage($this->t('Operating in maintenance mode.'), 'status', FALSE);
}
}
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.