Commit ac623bf9 authored by alexpott's avatar alexpott

Issue #2954825 by rakesh.gectcr, tresti88, gnuget, borisson_, DamienGR,...

Issue #2954825 by rakesh.gectcr, tresti88, gnuget, borisson_, DamienGR, Prashant.c, amietpatial, alexpott, joachim, Berdir: Update the user.api.php documentation and add the correct type hints in the user's hooks implementations

(cherry picked from commit 400413fa)
parent 84800034
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
use Drupal\field\FieldStorageConfigInterface; use Drupal\field\FieldStorageConfigInterface;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
use Drupal\user\RoleInterface; use Drupal\user\RoleInterface;
use Drupal\user\UserInterface;
/** /**
* Anonymous posters cannot enter their contact information. * Anonymous posters cannot enter their contact information.
...@@ -518,7 +519,7 @@ function comment_node_search_result(EntityInterface $node) { ...@@ -518,7 +519,7 @@ function comment_node_search_result(EntityInterface $node) {
/** /**
* Implements hook_user_cancel(). * Implements hook_user_cancel().
*/ */
function comment_user_cancel($edit, $account, $method) { function comment_user_cancel($edit, UserInterface $account, $method) {
switch ($method) { switch ($method) {
case 'user_cancel_block_unpublish': case 'user_cancel_block_unpublish':
$comments = entity_load_multiple_by_properties('comment', ['uid' => $account->id()]); $comments = entity_load_multiple_by_properties('comment', ['uid' => $account->id()]);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\user\UserInterface;
/** /**
* Entities changed before this time are always shown as read. * Entities changed before this time are always shown as read.
...@@ -159,7 +160,7 @@ function history_node_delete(EntityInterface $node) { ...@@ -159,7 +160,7 @@ function history_node_delete(EntityInterface $node) {
/** /**
* Implements hook_user_cancel(). * Implements hook_user_cancel().
*/ */
function history_user_cancel($edit, $account, $method) { function history_user_cancel($edit, UserInterface $account, $method) {
switch ($method) { switch ($method) {
case 'user_cancel_reassign': case 'user_cancel_reassign':
db_delete('history') db_delete('history')
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
use Drupal\node\Entity\NodeType; use Drupal\node\Entity\NodeType;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
use Drupal\node\NodeTypeInterface; use Drupal\node\NodeTypeInterface;
use Drupal\user\UserInterface;
/** /**
* Denotes that the node is not published. * Denotes that the node is not published.
...@@ -713,7 +714,7 @@ function node_ranking() { ...@@ -713,7 +714,7 @@ function node_ranking() {
/** /**
* Implements hook_user_cancel(). * Implements hook_user_cancel().
*/ */
function node_user_cancel($edit, $account, $method) { function node_user_cancel($edit, UserInterface $account, $method) {
switch ($method) { switch ($method) {
case 'user_cancel_block_unpublish': case 'user_cancel_block_unpublish':
// Unpublish nodes (current revisions). // Unpublish nodes (current revisions).
......
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
* Test module. * Test module.
*/ */
use Drupal\user\UserInterface;
/** /**
* Implements hook_user_login(). * Implements hook_user_login().
*/ */
function session_test_user_login($account) { function session_test_user_login(UserInterface $account) {
if ($account->getUsername() == 'session_test_user') { if ($account->getUsername() == 'session_test_user') {
// Exit so we can verify that the session was regenerated // Exit so we can verify that the session was regenerated
// before hook_user_login() was called. // before hook_user_login() was called.
......
...@@ -6,11 +6,12 @@ ...@@ -6,11 +6,12 @@
*/ */
use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Session\AccountInterface;
/** /**
* Implements hook_user_format_name_alter(). * Implements hook_user_format_name_alter().
*/ */
function user_hooks_test_user_format_name_alter(&$name, $account) { function user_hooks_test_user_format_name_alter(&$name, AccountInterface $account) {
if (\Drupal::state()->get('user_hooks_test_user_format_name_alter', FALSE)) { if (\Drupal::state()->get('user_hooks_test_user_format_name_alter', FALSE)) {
if (\Drupal::state()->get('user_hooks_test_user_format_name_alter_safe', FALSE)) { if (\Drupal::state()->get('user_hooks_test_user_format_name_alter_safe', FALSE)) {
$name = new FormattableMarkup('<em>@uid</em>', ['@uid' => $account->id()]); $name = new FormattableMarkup('<em>@uid</em>', ['@uid' => $account->id()]);
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
* Hooks provided by the User module. * Hooks provided by the User module.
*/ */
use Drupal\Core\Session\AccountInterface;
use Drupal\user\UserInterface;
/** /**
* @addtogroup hooks * @addtogroup hooks
* @{ * @{
...@@ -28,7 +31,7 @@ ...@@ -28,7 +31,7 @@
* *
* @param array $edit * @param array $edit
* The array of form values submitted by the user. * 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. * The user object on which the operation is being performed.
* @param string $method * @param string $method
* The account cancellation method. * The account cancellation method.
...@@ -36,7 +39,7 @@ ...@@ -36,7 +39,7 @@
* @see user_cancel_methods() * @see user_cancel_methods()
* @see hook_user_cancel_methods_alter() * @see hook_user_cancel_methods_alter()
*/ */
function hook_user_cancel($edit, $account, $method) { function hook_user_cancel($edit, UserInterface $account, $method) {
switch ($method) { switch ($method) {
case 'user_cancel_block_unpublish': case 'user_cancel_block_unpublish':
// Unpublish nodes (current revisions). // Unpublish nodes (current revisions).
...@@ -120,7 +123,7 @@ function hook_user_cancel_methods_alter(&$methods) { ...@@ -120,7 +123,7 @@ function hook_user_cancel_methods_alter(&$methods) {
* @see \Drupal\Core\Session\AccountInterface::getDisplayName() * @see \Drupal\Core\Session\AccountInterface::getDisplayName()
* @see sanitization * @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. // Display the user's uid instead of name.
if ($account->id()) { if ($account->id()) {
$name = t('User @uid', ['@uid' => $account->id()]); $name = t('User @uid', ['@uid' => $account->id()]);
...@@ -130,10 +133,10 @@ function hook_user_format_name_alter(&$name, $account) { ...@@ -130,10 +133,10 @@ function hook_user_format_name_alter(&$name, $account) {
/** /**
* The user just logged in. * The user just logged in.
* *
* @param object $account * @param \Drupal\user\UserInterface $account
* The user object on which the operation was just performed. * 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'); $config = \Drupal::config('system.date');
// If the user has a NULL time zone, notify them to set a time zone. // 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')) { if (!$account->getTimezone() && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) {
...@@ -151,10 +154,10 @@ function hook_user_login($account) { ...@@ -151,10 +154,10 @@ function hook_user_login($account) {
/** /**
* The user just logged out. * The user just logged out.
* *
* @param $account * @param \Drupal\Core\Session\AccountInterface $account
* The user object on which the operation was just performed. * The user object on which the operation was just performed.
*/ */
function hook_user_logout($account) { function hook_user_logout(AccountInterface $account) {
db_insert('logouts') db_insert('logouts')
->fields([ ->fields([
'uid' => $account->id(), 'uid' => $account->id(),
......
...@@ -569,7 +569,7 @@ function user_login_finalize(UserInterface $account) { ...@@ -569,7 +569,7 @@ function user_login_finalize(UserInterface $account) {
/** /**
* Implements hook_user_login(). * Implements hook_user_login().
*/ */
function user_user_login($account) { function user_user_login(UserInterface $account) {
// Reset static cache of default variables in template_preprocess() to reflect // Reset static cache of default variables in template_preprocess() to reflect
// the new user. // the new user.
drupal_static_reset('template_preprocess'); drupal_static_reset('template_preprocess');
...@@ -578,7 +578,7 @@ function user_user_login($account) { ...@@ -578,7 +578,7 @@ function user_user_login($account) {
/** /**
* Implements hook_user_logout(). * Implements hook_user_logout().
*/ */
function user_user_logout($account) { function user_user_logout(AccountInterface $account) {
// Reset static cache of default variables in template_preprocess() to reflect // Reset static cache of default variables in template_preprocess() to reflect
// the new user. // the new user.
drupal_static_reset('template_preprocess'); drupal_static_reset('template_preprocess');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment