function MaintenanceModeSubscriber::onMaintenanceModeRequest
Same name in this branch
- 9 core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber::onMaintenanceModeRequest()
Same name in other branches
- 10 core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\user\EventSubscriber\MaintenanceModeSubscriber::onMaintenanceModeRequest()
- 10 core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber::onMaintenanceModeRequest()
- 11.x core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\user\EventSubscriber\MaintenanceModeSubscriber::onMaintenanceModeRequest()
- 11.x core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber::onMaintenanceModeRequest()
Logout users if site is in maintenance mode and user is not exempt.
Parameters
\Symfony\Component\HttpKernel\Event\RequestEvent $event: The event to process.
File
-
core/
modules/ user/ src/ EventSubscriber/ MaintenanceModeSubscriber.php, line 79
Class
- MaintenanceModeSubscriber
- Maintenance mode subscriber to log out users.
Namespace
Drupal\user\EventSubscriberCode
public function onMaintenanceModeRequest(RequestEvent $event) {
// If the site is offline, log out unprivileged users.
if ($this->account
->isAuthenticated()) {
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.