Mercurial > hg > cmmr2012-drupal-site
diff core/modules/user/user.api.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children | 12f9dff5fda9 |
line wrap: on
line diff
--- a/core/modules/user/user.api.php Thu Feb 28 11:14:44 2019 +0000 +++ b/core/modules/user/user.api.php Thu Feb 28 13:11:55 2019 +0000 @@ -5,6 +5,9 @@ * Hooks provided by the User module. */ +use Drupal\Core\Session\AccountInterface; +use Drupal\user\UserInterface; + /** * @addtogroup hooks * @{ @@ -28,7 +31,7 @@ * * @param array $edit * The array of form values submitted by the user. - * @param \Drupal\Core\Session\AccountInterface $account + * @param \Drupal\user\UserInterface $account * The user object on which the operation is being performed. * @param string $method * The account cancellation method. @@ -36,7 +39,7 @@ * @see user_cancel_methods() * @see hook_user_cancel_methods_alter() */ -function hook_user_cancel($edit, $account, $method) { +function hook_user_cancel($edit, UserInterface $account, $method) { switch ($method) { case 'user_cancel_block_unpublish': // Unpublish nodes (current revisions). @@ -107,7 +110,8 @@ * * Called by $account->getDisplayName() to allow modules to alter the username * that is displayed. Can be used to ensure user privacy in situations where - * $account->getDisplayName() is too revealing. + * $account->getDisplayName() is too revealing. This hook is invoked both for + * user entities and the anonymous user session object. * * @param string|Drupal\Component\Render\MarkupInterface $name * The username that is displayed for a user. If a hook implementation changes @@ -115,12 +119,19 @@ * the implementation to ensure the user's name is escaped properly. String * values will be autoescaped. * @param \Drupal\Core\Session\AccountInterface $account - * The user object on which the operation is being performed. + * The object on which the operation is being performed. This object may be a + * user entity. If the object is an implementation of UserInterface you can + * use instanceof operator before accessing user entity methods. For example: + * @code + * if ($account instanceof UserInterface) { + * // Access user entity methods. + * } + * @endcode * * @see \Drupal\Core\Session\AccountInterface::getDisplayName() * @see sanitization */ -function hook_user_format_name_alter(&$name, $account) { +function hook_user_format_name_alter(&$name, AccountInterface $account) { // Display the user's uid instead of name. if ($account->id()) { $name = t('User @uid', ['@uid' => $account->id()]); @@ -130,24 +141,31 @@ /** * The user just logged in. * - * @param object $account + * @param \Drupal\user\UserInterface $account * The user object on which the operation was just performed. */ -function hook_user_login($account) { +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_set_message(t('Configure your <a href=":user-edit">account time zone setting</a>.', [':user-edit' => $account->url('edit-form', ['query' => \Drupal::destination()->getAsArray(), 'fragment' => 'edit-timezone'])])); + \Drupal::messenger() + ->addStatus(t('Configure your <a href=":user-edit">account time zone setting</a>.', [ + ':user-edit' => $account->url('edit-form', [ + 'query' => \Drupal::destination() + ->getAsArray(), + 'fragment' => 'edit-timezone', + ]), + ])); } } /** * The user just logged out. * - * @param $account + * @param \Drupal\Core\Session\AccountInterface $account * The user object on which the operation was just performed. */ -function hook_user_logout($account) { +function hook_user_logout(AccountInterface $account) { db_insert('logouts') ->fields([ 'uid' => $account->id(),