From 189d99ebea820e2c0b34adef38e12bf76fce11fb Mon Sep 17 00:00:00 2001 From: Bram Goffings Date: Tue, 8 May 2012 15:28:11 +0200 Subject: [PATCH] user type hinting --- core/includes/password.inc | 10 ++-- core/modules/block/block.module | 4 +- core/modules/comment/comment.module | 5 +- core/modules/contact/contact.module | 8 ++- core/modules/contact/contact.test | 6 ++- core/modules/field/field.api.php | 4 +- core/modules/field/field.module | 6 ++- core/modules/field/tests/field_test.field.inc | 3 +- core/modules/node/node.api.php | 12 ++-- core/modules/node/node.module | 25 +++++---- .../node_access_test/node_access_test.module | 3 +- .../node/tests/modules/node_test/node_test.module | 5 +- core/modules/openid/openid.api.php | 4 +- core/modules/openid/openid.module | 8 ++- core/modules/openid/tests/openid_test.module | 4 +- core/modules/overlay/overlay.module | 4 +- core/modules/poll/poll.module | 5 +- core/modules/shortcut/shortcut.admin.inc | 6 ++- core/modules/shortcut/shortcut.api.php | 4 +- core/modules/shortcut/shortcut.module | 20 ++++--- core/modules/statistics/statistics.module | 5 +- core/modules/system/system.module | 6 ++- .../tests/modules/session_test/session_test.module | 4 +- core/modules/user/user.api.php | 40 +++++++------- core/modules/user/user.module | 57 ++++++++++---------- core/modules/user/user.test | 12 +++-- 26 files changed, 152 insertions(+), 118 deletions(-) diff --git a/core/includes/password.inc b/core/includes/password.inc index b052a4a..7ce106f 100644 --- a/core/includes/password.inc +++ b/core/includes/password.inc @@ -13,6 +13,8 @@ * user_needs_new_hash() functions. */ + use Drupal\user\User; + /** * The standard log2 number of iterations for password stretching. This should * increase by 1 every Drupal version in order to counteract increases in the @@ -221,13 +223,13 @@ function user_hash_password($password, $count_log2 = 0) { * * @param $password * A plain-text password - * @param $account + * @param Drupal\user\User $account * A user object with at least the fields from the {users} table. * * @return * TRUE or FALSE. */ -function user_check_password($password, $account) { +function user_check_password($password, User $account) { if (substr($account->pass, 0, 2) == 'U$') { // This may be an updated password from user_update_7000(). Such hashes // have 'U' added as the first character and need an extra md5() (see the @@ -270,13 +272,13 @@ function user_check_password($password, $account) { * Alternative implementations of this function might use other criteria based * on the fields in $account. * - * @param $account + * @param Drupal\user\User $account * A user object with at least the fields from the {users} table. * * @return * TRUE or FALSE. */ -function user_needs_new_hash($account) { +function user_needs_new_hash(User $account) { // Check whether this was an updated password. if ((substr($account->pass, 0, 3) != '$S$') || (strlen($account->pass) != DRUPAL_HASH_LENGTH)) { return TRUE; diff --git a/core/modules/block/block.module b/core/modules/block/block.module index f7d8dc0..8740f3a 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -5,6 +5,8 @@ * Controls the visual building blocks a page is constructed with. */ +use Drupal\user\User; + /** * Denotes that a block is not enabled in any region and should not be shown. */ @@ -628,7 +630,7 @@ function block_form_user_profile_form_alter(&$form, &$form_state) { /** * Implements hook_user_presave(). */ -function block_user_presave($account) { +function block_user_presave(User $account) { if (isset($account->block)) { $account->data['block'] = $account->block; } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 79f2ecb..3f7f4ff 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -10,6 +10,7 @@ */ use Drupal\node\Node; +use Drupal\user\User; /** * Comment is awaiting approval. @@ -1412,7 +1413,7 @@ function comment_node_search_result(Node $node) { /** * Implements hook_user_cancel(). */ -function comment_user_cancel($edit, $account, $method) { +function comment_user_cancel($edit, User $account, $method) { switch ($method) { case 'user_cancel_block_unpublish': $comments = comment_load_multiple(array(), array('uid' => $account->uid)); @@ -1435,7 +1436,7 @@ function comment_user_cancel($edit, $account, $method) { /** * Implements hook_user_predelete(). */ -function comment_user_predelete($account) { +function comment_user_predelete(User $account) { $cids = db_query('SELECT c.cid FROM {comment} c WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol(); comment_delete_multiple($cids); } diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 48c12d9..07b361f 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -5,6 +5,8 @@ * Enables the use of personal and site-wide contact forms. */ +use Drupal\user\User; + /** * Implements hook_help(). */ @@ -109,12 +111,12 @@ function contact_menu() { /** * Access callback: Checks access for a user's personal contact form. * - * @param $account + * @param Drupal\user\User $account * The user object of the user whose contact form is being requested. * * @see contact_menu() */ -function _contact_personal_tab_access($account) { +function _contact_personal_tab_access(User $account) { global $user; // Anonymous users cannot have contact forms. @@ -233,7 +235,7 @@ function contact_form_user_profile_form_alter(&$form, &$form_state) { /** * Implements hook_user_presave(). */ -function contact_user_presave($account) { +function contact_user_presave(User $account) { $account->data['contact'] = isset($account->contact) ? $account->contact : variable_get('contact_default_status', 1); } diff --git a/core/modules/contact/contact.test b/core/modules/contact/contact.test index 490d8f8..83bf5cf 100644 --- a/core/modules/contact/contact.test +++ b/core/modules/contact/contact.test @@ -4,6 +4,8 @@ * Tests for the Contact module. */ +use Drupal\user\User; + /** * Tests the site-wide contact form. */ @@ -420,12 +422,12 @@ class ContactPersonalTestCase extends DrupalWebTestCase { /** * Fills out a user's personal contact form and submits it. * - * @param $account + * @param Drupal\user\User $account * A user object of the user being contacted. * @param $message * An optional array with the form fields being used. */ - protected function submitPersonalContact($account, array $message = array()) { + protected function submitPersonalContact(User $account, array $message = array()) { $message += array( 'subject' => $this->randomName(16), 'message' => $this->randomName(64), diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 44aa50b..3f7712d 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -2663,13 +2663,13 @@ function hook_field_storage_purge($entity_type, $entity, $field, $instance) { * The type of $entity; for example, 'node' or 'user'. * @param $entity * (optional) The entity for the operation. - * @param $account + * @param Drupal\user\User $account * (optional) The account to check; if not given use currently logged in user. * * @return * TRUE if the operation is allowed, and FALSE if the operation is denied. */ -function hook_field_access($op, $field, $entity_type, $entity, $account) { +function hook_field_access($op, $field, $entity_type, $entity, Drupal\user\User $account) { if ($field['field_name'] == 'field_of_interest' && $op == 'edit') { return user_access('edit field of interest', $account); } diff --git a/core/modules/field/field.module b/core/modules/field/field.module index ab67eb2..bbff7bb 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -4,6 +4,8 @@ * Attach custom data fields to Drupal entities. */ +use Drupal\user\User; + /* * Load all public Field API functions. Drupal currently has no * mechanism for auto-loading core APIs, so we have to load them on @@ -972,14 +974,14 @@ function field_has_data($field) { * The type of $entity; e.g., 'node' or 'user'. * @param $entity * (optional) The entity for the operation. - * @param $account + * @param Drupal\user\User $account * (optional) The account to check, if not given use currently logged in user. * * @return * TRUE if the operation is allowed; * FALSE if the operation is denied. */ -function field_access($op, $field, $entity_type, $entity = NULL, $account = NULL) { +function field_access($op, $field, $entity_type, $entity = NULL, User $account = NULL) { global $user; if (!isset($account)) { diff --git a/core/modules/field/tests/field_test.field.inc b/core/modules/field/tests/field_test.field.inc index 8933d8b..1d5f1b2 100644 --- a/core/modules/field/tests/field_test.field.inc +++ b/core/modules/field/tests/field_test.field.inc @@ -6,6 +6,7 @@ */ use Drupal\field\FieldException; +use Drupal\user\User; /** * Implements hook_field_info(). @@ -405,7 +406,7 @@ function field_test_default_value($entity_type, $entity, $field, $instance) { /** * Implements hook_field_access(). */ -function field_test_field_access($op, $field, $entity_type, $entity, $account) { +function field_test_field_access($op, $field, $entity_type, $entity, User $account) { if ($field['field_name'] == "field_no_{$op}_access") { return FALSE; } diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index ce3b784..087b331 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -179,7 +179,7 @@ * sure to restore your {node_access} record after node_access_rebuild() is * called. * - * @param $account + * @param Drupal\user\User $account * The user object whose grants are requested. * @param $op * The node operation to be performed, such as "view", "update", or "delete". @@ -194,7 +194,7 @@ * @see node_access_rebuild() * @ingroup node_access */ -function hook_node_grants($account, $op) { +function hook_node_grants(Drupal\user\User $account, $op) { if (user_access('access private content', $account)) { $grants['example'] = array(1); } @@ -361,7 +361,7 @@ function hook_node_access_records_alter(&$grants, Drupal\node\Node $node) { * * @param $grants * The $grants array returned by hook_node_grants(). - * @param $account + * @param Drupal\user\User $account * The user account requesting access to content. * @param $op * The operation being performed, 'view', 'update' or 'delete'. @@ -371,7 +371,7 @@ function hook_node_access_records_alter(&$grants, Drupal\node\Node $node) { * @see hook_node_access_records_alter() * @ingroup node_access */ -function hook_node_grants_alter(&$grants, $account, $op) { +function hook_node_grants_alter(&$grants, Drupal\user\User $account, $op) { // Our sample module never allows certain roles to edit or delete // content. Since some other node access modules might allow this // permission, we expressly remove it by returning an empty $grants @@ -592,7 +592,7 @@ function hook_node_load($nodes, $types) { * - "delete" * - "update" * - "view" - * @param object $account + * @param Drupal\user\User $account * The user object to perform the access check operation on. * * @return integer @@ -602,7 +602,7 @@ function hook_node_load($nodes, $types) { * * @ingroup node_access */ -function hook_node_access($node, $op, $account) { +function hook_node_access($node, $op, Drupal\user\User $account) { $type = is_string($node) ? $node : $node->type; $configured_types = node_permissions_get_configured_types(); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 8dbc060..7d04fac 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -4,6 +4,7 @@ use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Database\Query\SelectExtender; use Drupal\Core\Database\Query\SelectInterface; use Drupal\node\Node; +use Drupal\user\User; /** * @file @@ -1610,7 +1611,7 @@ function node_ranking() { /** * Implements hook_user_cancel(). */ -function node_user_cancel($edit, $account, $method) { +function node_user_cancel($edit, User $account, $method) { switch ($method) { case 'user_cancel_block_unpublish': // Unpublish nodes (current revisions). @@ -1648,7 +1649,7 @@ function node_user_cancel($edit, $account, $method) { /** * Implements hook_user_predelete(). */ -function node_user_predelete($account) { +function node_user_predelete(User $account) { // Delete nodes (current revisions). // @todo Introduce node_mass_delete() or make node_mass_update() more flexible. $nodes = db_select('node', 'n') @@ -1704,8 +1705,8 @@ function theme_node_search_admin($variables) { * The node to check. * @param $op * (optional) The specific operation being checked. Defaults to 'view.' - * @param object $account - * (optional) A user object representing the user for whom the operation is + * @param Drupal\user\User $account + * (optional) A user entity representing the user for whom the operation is * to be performed. Determines access for a user other than the current user. * * @return @@ -2792,7 +2793,7 @@ function node_form_system_themes_admin_form_submit($form, &$form_state) { * @param Drupal\node\Node|string $node * The node entity on which the operation is to be performed, or the node type * (e.g., 'forum') for the 'create' operation. - * @param $account + * @param Drupal\user\User $account * (optional) A user object representing the user for whom the operation is to * be performed. Determines access for a user other than the current user. * @@ -2801,7 +2802,7 @@ function node_form_system_themes_admin_form_submit($form, &$form_state) { * * @see node_menu() */ -function node_access($op, $node, $account = NULL) { +function node_access($op, $node, User $account = NULL) { $rights = &drupal_static(__FUNCTION__, array()); if (!$node || !in_array($op, array('view', 'update', 'delete', 'create'), TRUE)) { @@ -2901,7 +2902,7 @@ function node_access($op, $node, $account = NULL) { /** * Implements hook_node_access(). */ -function node_node_access($node, $op, $account) { +function node_node_access($node, $op, User $account) { $type = is_string($node) ? $node : $node->type; $configured_types = node_permissions_get_configured_types(); @@ -2994,15 +2995,15 @@ function node_permissions_get_configured_types() { * * @param $op * The operation that the user is trying to perform. - * @param $account - * (optional) The user object for the user performing the operation. If + * @param Drupal\user\User $account + * (optional) The user entity for the user performing the operation. If * omitted, the current user is used. * * @return * An associative array in which the keys are realms, and the values are * arrays of grants for those realms. */ -function node_access_grants($op, $account = NULL) { +function node_access_grants($op, User $account = NULL) { if (!isset($account)) { $account = $GLOBALS['user']; @@ -3028,7 +3029,7 @@ function node_access_grants($op, $account = NULL) { * 'node_access'; when this function returns TRUE, no node access joins are * added to the query. * - * @param $account + * @param Drupal\user\User $account * (optional) The user object for the user whose access is being checked. If * omitted, the current user is used. * @@ -3038,7 +3039,7 @@ function node_access_grants($op, $account = NULL) { * @see hook_node_grants() * @see _node_query_node_access_alter() */ -function node_access_view_all_nodes($account = NULL) { +function node_access_view_all_nodes(User $account = NULL) { global $user; if (!$account) { $account = $user; diff --git a/core/modules/node/tests/modules/node_access_test/node_access_test.module b/core/modules/node/tests/modules/node_access_test/node_access_test.module index cda5fdf..338366c 100644 --- a/core/modules/node/tests/modules/node_access_test/node_access_test.module +++ b/core/modules/node/tests/modules/node_access_test/node_access_test.module @@ -8,11 +8,12 @@ */ use Drupal\node\Node; +use Drupal\user\User; /** * Implements hook_node_grants(). */ -function node_access_test_node_grants($account, $op) { +function node_access_test_node_grants(User $account, $op) { $grants = array(); // First grant a grant to the author for own content. $grants['node_access_test_author'] = array($account->uid); diff --git a/core/modules/node/tests/modules/node_test/node_test.module b/core/modules/node/tests/modules/node_test/node_test.module index f541d10..6c5e504 100644 --- a/core/modules/node/tests/modules/node_test/node_test.module +++ b/core/modules/node/tests/modules/node_test/node_test.module @@ -7,6 +7,7 @@ */ use Drupal\node\Node; +use Drupal\user\User; /** * Implements hook_node_load(). @@ -54,7 +55,7 @@ function node_test_node_view(Node $node, $view_mode) { /** * Implements hook_node_grants(). */ -function node_test_node_grants($account, $op) { +function node_test_node_grants(User $account, $op) { // Give everyone full grants so we don't break other node tests. // Our node access tests asserts three realms of access. // See testGrantAlter(). @@ -117,7 +118,7 @@ function node_test_node_access_records_alter(&$grants, Node $node) { /** * Implements hook_node_grants_alter(). */ -function node_test_node_grants_alter(&$grants, $account, $op) { +function node_test_node_grants_alter(&$grants, User $account, $op) { // Return an empty array of grants to prove that we can alter by reference. $grants = array(); } diff --git a/core/modules/openid/openid.api.php b/core/modules/openid/openid.api.php index bd286ff..e39f5ae 100644 --- a/core/modules/openid/openid.api.php +++ b/core/modules/openid/openid.api.php @@ -29,11 +29,11 @@ function hook_openid_request_alter(&$request, $service) { * * @param $response * Response values from the OpenID Provider. - * @param $account + * @param Drupal\user\User $account * The Drupal user account that logged in * */ -function hook_openid_response($response, $account) { +function hook_openid_response($response, Drupal\user\User $account) { if (isset($response['openid.ns.ax'])) { _mymodule_store_ax_fields($response, $account); } diff --git a/core/modules/openid/openid.module b/core/modules/openid/openid.module index 3881320..8aa6ccc 100644 --- a/core/modules/openid/openid.module +++ b/core/modules/openid/openid.module @@ -5,6 +5,8 @@ * Implement OpenID Relying Party support for Drupal */ +use Drupal\user\User; + /** * Implements hook_menu(). */ @@ -83,7 +85,7 @@ function openid_help($path, $arg) { /** * Implements hook_user_insert(). */ -function openid_user_insert($account) { +function openid_user_insert(User $account) { if (!empty($account->openid_claimed_id)) { // The user has registered after trying to log in via OpenID. if (variable_get('user_email_verification', TRUE)) { @@ -100,7 +102,7 @@ function openid_user_insert($account) { * * Save openid_identifier to visitor cookie. */ -function openid_user_login(&$edit, $account) { +function openid_user_login(&$edit, User $account) { if (isset($_SESSION['openid'])) { // The user has logged in via OpenID. user_cookie_save(array_intersect_key($_SESSION['openid']['user_login_values'], array_flip(array('openid_identifier')))); @@ -113,7 +115,7 @@ function openid_user_login(&$edit, $account) { * * Delete any openid_identifier in visitor cookie. */ -function openid_user_logout($account) { +function openid_user_logout(User $account) { if (isset($_COOKIE['Drupal_visitor_openid_identifier'])) { user_cookie_delete('openid_identifier'); } diff --git a/core/modules/openid/tests/openid_test.module b/core/modules/openid/tests/openid_test.module index ac49dbd..25501f6 100644 --- a/core/modules/openid/tests/openid_test.module +++ b/core/modules/openid/tests/openid_test.module @@ -20,6 +20,8 @@ * key is used for verifying the signed messages from the provider. */ +use Drupal\user\User; + /** * Implements hook_menu(). */ @@ -365,7 +367,7 @@ function openid_test_openid_request_alter(&$request, $service) { /** * Implements hook_openid_response(). */ -function openid_test_openid_response($response, $account) { +function openid_test_openid_response($response, User $account) { variable_set('openid_test_hook_openid_response_response', $response); variable_set('openid_test_hook_openid_response_account', $account ? $account : FALSE); } diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index 02c0883..25f4bc4 100644 --- a/core/modules/overlay/overlay.module +++ b/core/modules/overlay/overlay.module @@ -5,6 +5,8 @@ * Displays the Drupal administration interface in an overlay. */ +use Drupal\user\User; + /** * Implements hook_help(). */ @@ -102,7 +104,7 @@ function overlay_form_user_profile_form_alter(&$form, &$form_state) { /** * Implements hook_user_presave(). */ -function overlay_user_presave($account) { +function overlay_user_presave(User $account) { if (isset($account->overlay)) { $account->data['overlay'] = $account->overlay; } diff --git a/core/modules/poll/poll.module b/core/modules/poll/poll.module index 2e36e0b..b29d7f3 100644 --- a/core/modules/poll/poll.module +++ b/core/modules/poll/poll.module @@ -7,6 +7,7 @@ */ use Drupal\node\Node; +use Drupal\user\User; /** * Implements hook_help(). @@ -961,7 +962,7 @@ function poll_cancel($form, &$form_state) { /** * Implements hook_user_cancel(). */ -function poll_user_cancel($edit, $account, $method) { +function poll_user_cancel($edit, User $account, $method) { switch ($method) { case 'user_cancel_reassign': db_update('poll_vote') @@ -975,7 +976,7 @@ function poll_user_cancel($edit, $account, $method) { /** * Implements hook_user_predelete(). */ -function poll_user_predelete($account) { +function poll_user_predelete(User $account) { db_delete('poll_vote') ->condition('uid', $account->uid) ->execute(); diff --git a/core/modules/shortcut/shortcut.admin.inc b/core/modules/shortcut/shortcut.admin.inc index 9010f90..7752857 100644 --- a/core/modules/shortcut/shortcut.admin.inc +++ b/core/modules/shortcut/shortcut.admin.inc @@ -5,6 +5,8 @@ * Administrative page callbacks for the shortcut module. */ +use Drupal\user\User; + /** * Returns the maximum number of shortcut "slots" available per shortcut set. * @@ -24,7 +26,7 @@ function shortcut_max_slots() { * An associative array containing the structure of the form. * @param $form_state * An associative array containing the current state of the form. - * @param $account + * @param Drupal\user\User $account * (optional) The user account whose shortcuts will be switched. Defaults to * the current logged-in user. * @@ -35,7 +37,7 @@ function shortcut_max_slots() { * @see shortcut_set_switch_validate() * @see shortcut_set_switch_submit() */ -function shortcut_set_switch($form, &$form_state, $account = NULL) { +function shortcut_set_switch($form, &$form_state, User $account = NULL) { global $user; if (!isset($account)) { $account = $user; diff --git a/core/modules/shortcut/shortcut.api.php b/core/modules/shortcut/shortcut.api.php index 717a7c9..2a185e1 100644 --- a/core/modules/shortcut/shortcut.api.php +++ b/core/modules/shortcut/shortcut.api.php @@ -24,13 +24,13 @@ * modules implement this hook, the last (i.e., highest weighted) module which * returns a valid shortcut set name will prevail. * - * @param $account + * @param Drupal\user\User $account * The user account whose default shortcut set is being requested. * @return * The name of the shortcut set that this module recommends for that user, if * there is one. */ -function hook_shortcut_default_set($account) { +function hook_shortcut_default_set(Drupal\user\User $account) { // Use a special set of default shortcuts for administrators only. if (in_array(variable_get('user_admin_role', 0), $account->roles)) { return variable_get('mymodule_shortcut_admin_default_set'); diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index be29dce..db445d9 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -5,6 +5,8 @@ * Allows users to manage customizable lists of shortcut links. */ +use Drupal\user\User; + /** * The name of the default shortcut set. * @@ -256,7 +258,7 @@ function shortcut_set_delete_access($shortcut_set) { /** * Access callback for switching the shortcut set assigned to a user account. * - * @param object $account + * @param Drupal\user\User $account * (optional) The user account whose shortcuts will be switched. If not set, * permissions will be checked for switching the logged-in user's own * shortcut set. @@ -265,7 +267,7 @@ function shortcut_set_delete_access($shortcut_set) { * TRUE if the current user has access to switch the shortcut set of the * provided account, FALSE otherwise. */ -function shortcut_set_switch_access($account = NULL) { +function shortcut_set_switch_access(User $account = NULL) { global $user; if (user_access('administer shortcuts')) { @@ -435,10 +437,10 @@ function shortcut_set_reset_link_weights(&$shortcut_set) { * * @param $shortcut_set * An object representing the shortcut set. - * @param $account + * @param Drupal\user\User $account * A user account that will be assigned to use the set. */ -function shortcut_set_assign_user($shortcut_set, $account) { +function shortcut_set_assign_user($shortcut_set, User $account) { db_merge('shortcut_set_users') ->key(array('uid' => $account->uid)) ->fields(array('set_name' => $shortcut_set->set_name)) @@ -451,7 +453,7 @@ function shortcut_set_assign_user($shortcut_set, $account) { * * The user will go back to using whatever default set applies. * - * @param $account + * @param Drupal\user\User $account * A user account that will be removed from the shortcut set assignment. * * @return @@ -459,7 +461,7 @@ function shortcut_set_assign_user($shortcut_set, $account) { * successfully removed from it. FALSE if the user was already not assigned * to any set. */ -function shortcut_set_unassign_user($account) { +function shortcut_set_unassign_user(User $account) { $deleted = db_delete('shortcut_set_users') ->condition('uid', $account->uid) ->execute(); @@ -469,7 +471,7 @@ function shortcut_set_unassign_user($account) { /** * Returns the current displayed shortcut set for the provided user account. * - * @param $account + * @param Drupal\user\User $account * (optional) The user account whose shortcuts will be returned. Defaults to * the currently logged-in user. * @@ -478,7 +480,7 @@ function shortcut_set_unassign_user($account) { * current user. If the user does not have an explicit shortcut set defined, * the default set is returned. */ -function shortcut_current_displayed_set($account = NULL) { +function shortcut_current_displayed_set(User $account = NULL) { $shortcut_sets = &drupal_static(__FUNCTION__, array()); global $user; if (!isset($account)) { @@ -510,7 +512,7 @@ function shortcut_current_displayed_set($account = NULL) { /** * Returns the default shortcut set for a given user account. * - * @param object $account + * @param $account * (optional) The user account whose default shortcut set will be returned. * If not provided, the function will return the currently logged-in user's * default shortcut set. diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index ef1bceb..8e61902 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -6,6 +6,7 @@ */ use Drupal\node\Node; +use Drupal\user\User; /** * Implements hook_help(). @@ -206,7 +207,7 @@ function statistics_menu() { /** * Implements hook_user_cancel(). */ -function statistics_user_cancel($edit, $account, $method) { +function statistics_user_cancel($edit, User $account, $method) { switch ($method) { case 'user_cancel_reassign': db_update('accesslog') @@ -220,7 +221,7 @@ function statistics_user_cancel($edit, $account, $method) { /** * Implements hook_user_predelete(). */ -function statistics_user_predelete($account) { +function statistics_user_predelete(User $account) { db_delete('accesslog') ->condition('uid', $account->uid) ->execute(); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 987137b..a56b78f 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -5,6 +5,8 @@ * Configuration system that lets administrators modify the workings of the site. */ +use Drupal\user\User; + /** * Maximum age of temporary files in seconds. */ @@ -2040,7 +2042,7 @@ function system_form_user_register_form_alter(&$form, &$form_state) { /** * Implements hook_user_presave(). */ -function system_user_presave($account) { +function system_user_presave(User $account) { if (variable_get('configurable_timezones', 1) && empty($account->timezone) && !variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT)) { $account->timezone = variable_get('date_default_timezone', ''); } @@ -2049,7 +2051,7 @@ function system_user_presave($account) { /** * Implements hook_user_login(). */ -function system_user_login(&$edit, $account) { +function system_user_login(&$edit, User $account) { // If the user has a NULL time zone, notify them to set a time zone. if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) { drupal_set_message(t('Configure your account time zone setting.', array('@user-edit' => url("user/$account->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone'))))); diff --git a/core/modules/system/tests/modules/session_test/session_test.module b/core/modules/system/tests/modules/session_test/session_test.module index 689ff09..c1fe030 100644 --- a/core/modules/system/tests/modules/session_test/session_test.module +++ b/core/modules/system/tests/modules/session_test/session_test.module @@ -1,5 +1,7 @@ name == 'session_test_user') { // Exit so we can verify that the session was regenerated // before hook_user() was called. diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php index 8c7286e..3a5aab6 100644 --- a/core/modules/user/user.api.php +++ b/core/modules/user/user.api.php @@ -40,13 +40,13 @@ function hook_user_load($users) { * Modules should additionally implement hook_user_cancel() to process stored * user data for other account cancellation methods. * - * @param $account + * @param Drupal\user\User $account * The account that is about to be deleted. * * @see hook_user_delete() * @see user_delete_multiple() */ -function hook_user_predelete($account) { +function hook_user_predelete(Drupal\user\User $account) { db_delete('mytable') ->condition('uid', $account->uid) ->execute(); @@ -61,13 +61,13 @@ function hook_user_predelete($account) { * Modules should additionally implement hook_user_cancel() to process stored * user data for other account cancellation methods. * - * @param $account + * @param Drupal\user\User $account * The account that has been deleted. * * @see hook_user_predelete() * @see user_delete_multiple() */ -function hook_user_delete($account) { +function hook_user_delete(Drupal\user\User $account) { drupal_set_message(t('User: @name has been deleted.', array('@name' => $account->name))); } @@ -89,7 +89,7 @@ function hook_user_delete($account) { * * @param $edit * The array of form values submitted by the user. - * @param $account + * @param Drupal\user\User $account * The user object on which the operation is being performed. * @param $method * The account cancellation method. @@ -97,7 +97,7 @@ function hook_user_delete($account) { * @see user_cancel_methods() * @see hook_user_cancel_methods_alter() */ -function hook_user_cancel($edit, $account, $method) { +function hook_user_cancel($edit, Drupal\user\User $account, $method) { switch ($method) { case 'user_cancel_block_unpublish': // Unpublish nodes (current revisions). @@ -180,12 +180,12 @@ function hook_user_cancel_methods_alter(&$methods) { * @param $name * The string that user_format_name() will return. * - * @param $account + * @param Drupal\user\User $account * The account object passed to user_format_name(). * * @see user_format_name() */ -function hook_user_format_name_alter(&$name, $account) { +function hook_user_format_name_alter(&$name, Drupal\user\User $account) { // Display the user's uid instead of name. if (isset($account->uid)) { $name = t('User !uid', array('!uid' => $account->uid)); @@ -236,13 +236,13 @@ function hook_user_operations() { * add their properties to $account->data in order to have their data serialized * on save. * - * @param $account + * @param Drupal\user\User $account * The user account object. * * @see hook_user_insert() * @see hook_user_update() */ -function hook_user_presave($account) { +function hook_user_presave(Drupal\user\User $account) { // Make sure that our form value 'mymodule_foo' is stored as // 'mymodule_bar' in the 'data' (serialized) column. if (isset($account->mymodule_foo)) { @@ -253,13 +253,13 @@ function hook_user_presave($account) { /** * Respond to creation of a new user account. * - * @param $account + * @param Drupal\user\User $account * The user account object. * * @see hook_user_presave() * @see hook_user_update() */ -function hook_user_insert($account) { +function hook_user_insert(Drupal\user\User $account) { db_insert('user_changes') ->fields(array( 'uid' => $account->uid, @@ -271,13 +271,13 @@ function hook_user_insert($account) { /** * Respond to updates to a user account. * - * @param $account + * @param Drupal\user\User $account * The user account object. * * @see hook_user_presave() * @see hook_user_insert() */ -function hook_user_update($account) { +function hook_user_update(Drupal\user\User $account) { db_insert('user_changes') ->fields(array( 'uid' => $account->uid, @@ -291,10 +291,10 @@ function hook_user_update($account) { * * @param $edit * The array of form values submitted by the user. - * @param $account + * @param Drupal\user\User $account * The user object on which the operation was just performed. */ -function hook_user_login(&$edit, $account) { +function hook_user_login(&$edit, Drupal\user\User $account) { // If the user has a NULL time zone, notify them to set a time zone. if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) { drupal_set_message(t('Configure your account time zone setting.', array('@user-edit' => url("user/$account->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone'))))); @@ -304,10 +304,10 @@ function hook_user_login(&$edit, $account) { /** * The user just logged out. * - * @param $account + * @param Drupal\user\User $account * The user object on which the operation was just performed. */ -function hook_user_logout($account) { +function hook_user_logout(Drupal\user\User $account) { db_insert('logouts') ->fields(array( 'uid' => $account->uid, @@ -322,7 +322,7 @@ function hook_user_logout($account) { * The module should format its custom additions for display and add them to the * $account->content array. * - * @param $account + * @param Drupal\user\User $account * The user object on which the operation is being performed. * @param $view_mode * View mode, e.g. 'full'. @@ -332,7 +332,7 @@ function hook_user_logout($account) { * @see hook_user_view_alter() * @see hook_entity_view() */ -function hook_user_view($account, $view_mode, $langcode) { +function hook_user_view(Drupal\user\User $account, $view_mode, $langcode) { $account->content['user_picture'] = array( '#markup' => theme('user_picture', array('account' => $account)), '#weight' => -10, diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 836f101..494dbd7 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1,6 +1,7 @@ content['user_picture'] = array( '#markup' => theme('user_picture', array('account' => $account)), '#weight' => -10, @@ -1200,7 +1201,7 @@ function user_preprocess_block(&$variables) { * * @see hook_user_format_name_alter() * - * @param $account + * @param Drupal\user\User $account * The account object for the user whose name is to be formatted. * * @return @@ -1413,10 +1414,10 @@ function user_register_access() { /** * User view access callback. * - * @param $account + * @param Drupal\user\User $account * Can either be a full user object or a $uid. */ -function user_view_access($account) { +function user_view_access(User $account) { $uid = is_object($account) ? $account->uid : (int) $account; // Never allow access to view the anonymous user account. @@ -1439,7 +1440,7 @@ function user_view_access($account) { /** * Access callback for user account editing. */ -function user_edit_access($account) { +function user_edit_access(User $account) { return (($GLOBALS['user']->uid == $account->uid) || user_access('administer users')) && $account->uid > 0; } @@ -1449,7 +1450,7 @@ function user_edit_access($account) { * Limit access to users with the 'cancel account' permission or administrative * users, and prevent the anonymous user from cancelling the account. */ -function user_cancel_access($account) { +function user_cancel_access(User $account) { return ((($GLOBALS['user']->uid == $account->uid) && user_access('cancel account')) || user_access('administer users')) && $account->uid > 0; } @@ -1823,15 +1824,15 @@ function user_get_authmaps($authname = NULL) { * Save mappings of which external authentication module(s) authenticated * a user. Maps external usernames to user ids in the users table. * - * @param $account - * A user object. + * @param Drupal\user\User $account + * A user entity. * @param $authmaps * An associative array with a compound key and the username as the value. * The key is made up of 'authname_' plus the name of the external authentication * module. * @see user_external_login_register() */ -function user_set_authmaps($account, $authmaps) { +function user_set_authmaps(User $account, $authmaps) { foreach ($authmaps as $key => $value) { $module = explode('_', $key, 2); if ($value) { @@ -2103,14 +2104,14 @@ function user_external_login_register($name, $module) { /** * Generates a unique URL for a user to login and reset their password. * - * @param object $account - * An object containing the user account. + * @param Drupal\user\User $account + * An entity containing the user account. * * @return * A unique URL that provides a one-time log in for the user, from which * they can change their password. */ -function user_pass_reset_url($account) { +function user_pass_reset_url(User $account) { $timestamp = REQUEST_TIME; return url("user/reset/$account->uid/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login), array('absolute' => TRUE)); } @@ -2118,8 +2119,8 @@ function user_pass_reset_url($account) { /** * Generates a URL to confirm an account cancellation request. * - * @param object $account - * The user account object, which must contain at least the following + * @param Drupal\user\User $account + * The user account entity, which must contain at least the following * properties: * - uid: The user uid number. * - pass: The hashed user password string. @@ -2132,7 +2133,7 @@ function user_pass_reset_url($account) { * @see user_mail_tokens() * @see user_cancel_confirm() */ -function user_cancel_url($account) { +function user_cancel_url(User $account) { $timestamp = REQUEST_TIME; return url("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login), array('absolute' => TRUE)); } @@ -2225,7 +2226,7 @@ function user_cancel($edit, $uid, $method) { * * @see user_cancel() */ -function _user_cancel($edit, $account, $method) { +function _user_cancel($edit, User $account, $method) { global $user; switch ($method) { @@ -2345,8 +2346,8 @@ function user_view_page($account) { * To theme user profiles, copy modules/user/user-profile.tpl.php * to your theme directory, and edit it as instructed in that file's comments. * - * @param $account - * A user object. + * @param Drupal\user\User $account + * A user entity. * @param $view_mode * View mode, e.g. 'full'. * @param $langcode @@ -2356,7 +2357,7 @@ function user_view_page($account) { * @return * An array as expected by drupal_render(). */ -function user_view($account, $view_mode = 'full', $langcode = NULL) { +function user_view(User $account, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { $langcode = $GLOBALS['language_content']->langcode; } @@ -2385,15 +2386,15 @@ function user_view($account, $view_mode = 'full', $langcode = NULL) { /** * Builds a structured array representing the profile content. * - * @param $account - * A user object. + * @param Drupal\user\User $account + * A user entity. * @param $view_mode * View mode, e.g. 'full'. * @param $langcode * (optional) A language code to use for rendering. Defaults to the global * content language of the current request. */ -function user_build_content($account, $view_mode = 'full', $langcode = NULL) { +function user_build_content(User $account, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { $langcode = $GLOBALS['language_content']->langcode; } @@ -3277,13 +3278,13 @@ function theme_user_signature($variables) { * choose a preferred language, or is the anonymous user, the $default * value, or if it is not set, the site default language will be returned. * - * @param $account + * @param Drupal\user\User $account * User account to look up language for. * @param $default * Optional default language object to return if the account * has no valid language. */ -function user_preferred_language($account, $default = NULL) { +function user_preferred_language(User $account, $default = NULL) { $language_list = language_list(); if (!empty($account->preferred_langcode) && isset($language_list[$account->preferred_langcode])) { return $language_list[$account->preferred_langcode]; @@ -3313,7 +3314,7 @@ function user_preferred_language($account, $default = NULL) { * - 'cancel_confirm': Account cancellation request. * - 'status_canceled': Account canceled. * - * @param $account + * @param Drupal\user\User $account * The user object of the account being notified. Must contain at * least the fields 'uid', 'name', and 'mail'. * @param $language @@ -3323,7 +3324,7 @@ function user_preferred_language($account, $default = NULL) { * The return value from drupal_mail_system()->mail(), if ends up being * called. */ -function _user_mail_notify($op, $account, $language = NULL) { +function _user_mail_notify($op, User $account, $language = NULL) { // By default, we always notify except for canceled and blocked. $default_notify = ($op != 'status_canceled' && $op != 'status_blocked'); $notify = variable_get('user_mail_' . $op . '_notify', $default_notify); diff --git a/core/modules/user/user.test b/core/modules/user/user.test index 0ce6870..1dbf227 100644 --- a/core/modules/user/user.test +++ b/core/modules/user/user.test @@ -5,6 +5,8 @@ * Tests for user.module. */ +use Drupal\user\User; + class UserRegistrationTestCase extends DrupalWebTestCase { public static function getInfo() { return array( @@ -410,13 +412,13 @@ class UserLoginTestCase extends DrupalWebTestCase { /** * Make an unsuccessful login attempt. * - * @param $account - * A user object with name and pass_raw attributes for the login attempt. + * @param Drupal\user\User $account + * A user entity with name and pass_raw attributes for the login attempt. * @param $flood_trigger * Whether or not to expect that the flood control mechanism will be * triggered. */ - function assertFailedLogin($account, $flood_trigger = NULL) { + function assertFailedLogin(User $account, $flood_trigger = NULL) { $edit = array( 'name' => $account->name, 'pass' => $account->pass_raw, @@ -2257,11 +2259,11 @@ class UserRolesAssignmentTestCase extends DrupalWebTestCase { /** * Check role on user object. * - * @param object $account User. + * @param Drupal\user\User $account. * @param integer $rid Role id. * @param bool $is_assigned True if the role should present on the account. */ - private function userLoadAndCheckRoleAssigned($account, $rid, $is_assigned = TRUE) { + private function userLoadAndCheckRoleAssigned(User $account, $rid, $is_assigned = TRUE) { $account = user_load($account->uid, TRUE); if ($is_assigned) { $this->assertTrue(array_key_exists($rid, $account->roles), t('The role is present in the user object.')); -- 1.7.4.msysgit.0