function hook_user_logout

Same name and namespace in other branches
  1. 7.x modules/user/user.api.php \hook_user_logout()
  2. 8.9.x core/modules/user/user.api.php \hook_user_logout()
  3. 10 core/modules/user/user.api.php \hook_user_logout()
  4. 11.x core/modules/user/user.api.php \hook_user_logout()

The user just logged out.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user object on which the operation was just performed.

Related topics

2 functions implement hook_user_logout()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

UserHooks::userLogout in core/modules/user/src/Hook/UserHooks.php
Implements hook_user_logout().
user_user_logout in core/modules/user/user.module
Implements hook_user_logout().
1 invocation of hook_user_logout()
user_logout in core/modules/user/user.module
Logs the current user out.

File

core/modules/user/user.api.php, line 170

Code

function hook_user_logout(AccountInterface $account) {
    \Drupal::database()->insert('logouts')
        ->fields([
        'uid' => $account->id(),
        'time' => time(),
    ])
        ->execute();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.