You are here

function user_logout in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/user.module \user_logout()
  2. 4 modules/user.module \user_logout()
  3. 5 modules/user/user.module \user_logout()
  4. 6 modules/user/user.pages.inc \user_logout()
  5. 7 modules/user/user.pages.inc \user_logout()
  6. 9 core/modules/user/user.module \user_logout()

Logs the current user out.

4 calls to user_logout()
MaintenanceModeSubscriber::onMaintenanceModeRequest in core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php
Logout users if site is in maintenance mode and user is not exempt.
UserAuthenticationController::userLogout in core/modules/user/src/Controller/UserAuthenticationController.php
Logs the user out.
UserController::logout in core/modules/user/src/Controller/UserController.php
Logs the current user out.
UserController::resetPass in core/modules/user/src/Controller/UserController.php
Redirects to the user password reset form.
4 string references to 'user_logout'
drupal6.php in core/modules/migrate_drupal/tests/fixtures/drupal6.php
A database agnostic dump for testing purposes.
drupal7.php in core/modules/tracker/tests/fixtures/drupal7.php
A database agnostic dump for testing purposes.
drupal7.php in core/modules/rdf/tests/fixtures/drupal7.php
A database agnostic dump for testing purposes.
drupal7.php in core/modules/migrate_drupal/tests/fixtures/drupal7.php
A database agnostic dump for testing purposes.

File

core/modules/user/user.module, line 1197
Enables the user registration and login system.

Code

function user_logout() {
  $user = \Drupal::currentUser();
  \Drupal::logger('user')
    ->notice('Session closed for %name.', [
    '%name' => $user
      ->getAccountName(),
  ]);
  \Drupal::moduleHandler()
    ->invokeAll('user_logout', [
    $user,
  ]);

  // Destroy the current session, and reset $user to the anonymous user.
  // Note: In Symfony the session is intended to be destroyed with
  // Session::invalidate(). Regrettably this method is currently broken and may
  // lead to the creation of spurious session records in the database.
  // @see https://github.com/symfony/symfony/issues/12375
  \Drupal::service('session_manager')
    ->destroy();
  $user
    ->setAccount(new AnonymousUserSession());
}