function hook_user_login

Same name in other branches
  1. 7.x modules/user/user.api.php \hook_user_login()
  2. 9 core/modules/user/user.api.php \hook_user_login()
  3. 8.9.x core/modules/user/user.api.php \hook_user_login()
  4. 11.x core/modules/user/user.api.php \hook_user_login()

The user just logged in.

Parameters

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

Related topics

2 functions implement hook_user_login()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

session_test_user_login in core/modules/system/tests/modules/session_test/session_test.module
Implements hook_user_login().
user_user_login in core/modules/user/user.module
Implements hook_user_login().
1 invocation of hook_user_login()
user_login_finalize in core/modules/user/user.module
Finalizes the login process and logs in a user.

File

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

Code

function hook_user_login(UserInterface $account) {
    $config = \Drupal::config('system.date');
    // If the user has a NULL time zone, notify them to set a time zone.
    if (!$account->getTimezone() && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) {
        \Drupal::messenger()->addStatus(t('Configure your <a href=":user-edit">account time zone setting</a>.', [
            ':user-edit' => $account->toUrl('edit-form', [
                'query' => \Drupal::destination()->getAsArray(),
                'fragment' => 'edit-timezone',
            ])
                ->toString(),
        ]));
    }
}

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