function MaintenanceModeSubscriber::onKernelRequestMaintenance
Same name in this branch
- 9 core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber::onKernelRequestMaintenance()
Same name in other branches
- 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()
- 11.x core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber::onKernelRequestMaintenance()
Logout users if site is in maintenance mode.
Parameters
\Symfony\Component\HttpKernel\Event\RequestEvent $event: The event to process.
Deprecated
in drupal:9.4.0 and is removed from drupal:10.0.0. Use \Drupal\user\EventSubscriber::onMaintenanceModeRequest() instead.
See also
https://www.drupal.org/node/3255799
File
-
core/
modules/ user/ src/ EventSubscriber/ MaintenanceModeSubscriber.php, line 57
Class
- MaintenanceModeSubscriber
- Maintenance mode subscriber to log out users.
Namespace
Drupal\user\EventSubscriberCode
public function onKernelRequestMaintenance(RequestEvent $event) {
@trigger_error('\\Drupal\\user\\EventSubscriber::onKernelRequestMaintenance() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use \\Drupal\\user\\EventSubscriber::onMaintenanceModeRequest() instead. See https://www.drupal.org/node/3255799', E_USER_DEPRECATED);
$request = $event->getRequest();
$route_match = RouteMatch::createFromRequest($request);
if ($this->maintenanceMode
->applies($route_match)) {
// If the site is offline, log out unprivileged users.
if ($this->account
->isAuthenticated() && !$this->maintenanceMode
->exempt($this->account)) {
user_logout();
// Redirect to homepage.
$event->setResponse(new RedirectResponse(Url::fromRoute('<front>')->toString()));
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.