You are here

public function MaintenanceModeSubscriber::onMaintenanceModeRequest in Drupal 10

Same name in this branch
  1. 10 core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\Core\EventSubscriber\MaintenanceModeSubscriber::onMaintenanceModeRequest()
  2. 10 core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php \Drupal\user\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 51

Class

MaintenanceModeSubscriber
Maintenance mode subscriber to log out users.

Namespace

Drupal\user\EventSubscriber

Code

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()));
  }
}