Mercurial > hg > cmmr2012-drupal-site
diff core/modules/user/user.module @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
line wrap: on
line diff
--- a/core/modules/user/user.module Thu Feb 28 13:11:55 2019 +0000 +++ b/core/modules/user/user.module Thu May 09 15:34:47 2019 +0100 @@ -8,6 +8,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Component\Render\PlainTextOutput; use Drupal\Component\Utility\Unicode; +use Drupal\Core\Access\AccessibleInterface; use Drupal\Core\Asset\AttachedAssetsInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Field\BaseFieldDefinition; @@ -79,15 +80,15 @@ $output .= '<h3>' . t('Uses') . '</h3>'; $output .= '<dl>'; $output .= '<dt>' . t('Creating and managing users') . '</dt>'; - $output .= '<dd>' . t('Through the <a href=":people">People administration page</a> you can add and cancel user accounts and assign users to roles. By editing one particular user you can change their username, email address, password, and information in other fields.', [':people' => \Drupal::url('entity.user.collection')]) . '</dd>'; + $output .= '<dd>' . t('Through the <a href=":people">People administration page</a> you can add and cancel user accounts and assign users to roles. By editing one particular user you can change their username, email address, password, and information in other fields.', [':people' => Url::fromRoute('entity.user.collection')->toString()]) . '</dd>'; $output .= '<dt>' . t('Configuring user roles') . '</dt>'; - $output .= '<dd>' . t('<em>Roles</em> are used to group and classify users; each user can be assigned one or more roles. Typically there are two pre-defined roles: <em>Anonymous user</em> (users that are not logged in), and <em>Authenticated user</em> (users that are registered and logged in). Depending on how your site was set up, an <em>Administrator</em> role may also be available: users with this role will automatically be assigned any new permissions whenever a module is enabled. You can create additional roles on the <a href=":roles">Roles administration page</a>.', [':roles' => \Drupal::url('entity.user_role.collection')]) . '</dd>'; + $output .= '<dd>' . t('<em>Roles</em> are used to group and classify users; each user can be assigned one or more roles. Typically there are two pre-defined roles: <em>Anonymous user</em> (users that are not logged in), and <em>Authenticated user</em> (users that are registered and logged in). Depending on how your site was set up, an <em>Administrator</em> role may also be available: users with this role will automatically be assigned any new permissions whenever a module is enabled. You can create additional roles on the <a href=":roles">Roles administration page</a>.', [':roles' => Url::fromRoute('entity.user_role.collection')->toString()]) . '</dd>'; $output .= '<dt>' . t('Setting permissions') . '</dt>'; - $output .= '<dd>' . t('After creating roles, you can set permissions for each role on the <a href=":permissions_user">Permissions page</a>. Granting a permission allows users who have been assigned a particular role to perform an action on the site, such as viewing content, editing or creating a particular type of content, administering settings for a particular module, or using a particular function of the site (such as search).', [':permissions_user' => \Drupal::url('user.admin_permissions')]) . '</dd>'; + $output .= '<dd>' . t('After creating roles, you can set permissions for each role on the <a href=":permissions_user">Permissions page</a>. Granting a permission allows users who have been assigned a particular role to perform an action on the site, such as viewing content, editing or creating a particular type of content, administering settings for a particular module, or using a particular function of the site (such as search).', [':permissions_user' => Url::fromRoute('user.admin_permissions')->toString()]) . '</dd>'; $output .= '<dt>' . t('Managing account settings') . '</dt>'; - $output .= '<dd>' . t('The <a href=":accounts">Account settings page</a> allows you to manage settings for the displayed name of the Anonymous user role, personal contact forms, user registration settings, and account cancellation settings. On this page you can also manage settings for account personalization, and adapt the text for the email messages that users receive when they register or request a password recovery. You may also set which role is automatically assigned new permissions whenever a module is enabled (the Administrator role).', [':accounts' => \Drupal::url('entity.user.admin_form')]) . '</dd>'; + $output .= '<dd>' . t('The <a href=":accounts">Account settings page</a> allows you to manage settings for the displayed name of the Anonymous user role, personal contact forms, user registration settings, and account cancellation settings. On this page you can also manage settings for account personalization, and adapt the text for the email messages that users receive when they register or request a password recovery. You may also set which role is automatically assigned new permissions whenever a module is enabled (the Administrator role).', [':accounts' => Url::fromRoute('entity.user.admin_form')->toString()]) . '</dd>'; $output .= '<dt>' . t('Managing user account fields') . '</dt>'; - $output .= '<dd>' . t('Because User accounts are an entity type, you can extend them by adding fields through the Manage fields tab on the <a href=":accounts">Account settings page</a>. By adding fields for e.g., a picture, a biography, or address, you can a create a custom profile for the users of the website. For background information on entities and fields, see the <a href=":field_help">Field module help page</a>.', [':field_help' => (\Drupal::moduleHandler()->moduleExists('field')) ? \Drupal::url('help.page', ['name' => 'field']) : '#', ':accounts' => \Drupal::url('entity.user.admin_form')]) . '</dd>'; + $output .= '<dd>' . t('Because User accounts are an entity type, you can extend them by adding fields through the Manage fields tab on the <a href=":accounts">Account settings page</a>. By adding fields for e.g., a picture, a biography, or address, you can a create a custom profile for the users of the website. For background information on entities and fields, see the <a href=":field_help">Field module help page</a>.', [':field_help' => (\Drupal::moduleHandler()->moduleExists('field')) ? Url::fromRoute('help.page', ['name' => 'field'])->toString() : '#', ':accounts' => Url::fromRoute('entity.user.admin_form')->toString()]) . '</dd>'; $output .= '</dl>'; return $output; @@ -95,10 +96,10 @@ return '<p>' . t("This web page allows administrators to register new users. Users' email addresses and usernames must be unique.") . '</p>'; case 'user.admin_permissions': - return '<p>' . t('Permissions let you control what users can do and see on your site. You can define a specific set of permissions for each role. (See the <a href=":role">Roles</a> page to create a role.) Any permissions granted to the Authenticated user role will be given to any user who is logged in to your site. From the <a href=":settings">Account settings</a> page, you can make any role into an Administrator role for the site, meaning that role will be granted all new permissions automatically. You should be careful to ensure that only trusted users are given this access and level of control of your site.', [':role' => \Drupal::url('entity.user_role.collection'), ':settings' => \Drupal::url('entity.user.admin_form')]) . '</p>'; + return '<p>' . t('Permissions let you control what users can do and see on your site. You can define a specific set of permissions for each role. (See the <a href=":role">Roles</a> page to create a role.) Any permissions granted to the Authenticated user role will be given to any user who is logged in to your site. From the <a href=":settings">Account settings</a> page, you can make any role into an Administrator role for the site, meaning that role will be granted all new permissions automatically. You should be careful to ensure that only trusted users are given this access and level of control of your site.', [':role' => Url::fromRoute('entity.user_role.collection')->toString(), ':settings' => Url::fromRoute('entity.user.admin_form')->toString()]) . '</p>'; case 'entity.user_role.collection': - return '<p>' . t('A role defines a group of users that have certain privileges. These privileges are defined on the <a href=":permissions">Permissions page</a>. Here, you can define the names and the display sort order of the roles on your site. It is recommended to order roles from least permissive (for example, Anonymous user) to most permissive (for example, Administrator user). Users who are not logged in have the Anonymous user role. Users who are logged in have the Authenticated user role, plus any other roles granted to their user account.', [':permissions' => \Drupal::url('user.admin_permissions')]) . '</p>'; + return '<p>' . t('A role defines a group of users that have certain privileges. These privileges are defined on the <a href=":permissions">Permissions page</a>. Here, you can define the names and the display sort order of the roles on your site. It is recommended to order roles from least permissive (for example, Anonymous user) to most permissive (for example, Administrator user). Users who are not logged in have the Anonymous user role. Users who are logged in have the Authenticated user role, plus any other roles granted to their user account.', [':permissions' => Url::fromRoute('user.admin_permissions')->toString()]) . '</p>'; case 'entity.user.field_ui_fields': return '<p>' . t('This form lets administrators add and edit fields for storing user data.') . '</p>'; @@ -199,16 +200,13 @@ * @return array * An array of user objects, indexed by uid. * - * @see entity_load_multiple() - * @see \Drupal\user\Entity\User::load() - * @see user_load_by_mail() - * @see user_load_by_name() - * @see \Drupal\Core\Entity\Query\QueryInterface + * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * \Drupal\user\Entity\User::loadMultiple(). * - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. - * Use \Drupal\user\Entity\User::loadMultiple(). + * @see https://www.drupal.org/node/2266845 */ function user_load_multiple(array $uids = NULL, $reset = FALSE) { + @trigger_error('user_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\user\Entity\User::loadMultiple(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); if ($reset) { \Drupal::entityManager()->getStorage('user')->resetCache($uids); } @@ -228,12 +226,13 @@ * A fully-loaded user object upon successful user load, or NULL if the user * cannot be loaded. * - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. - * Use \Drupal\user\Entity\User::load(). + * @deprecated iin Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use + * Drupal\user\Entity\User::load(). * - * @see \Drupal\user\Entity\User::loadMultiple() + * @see https://www.drupal.org/node/2266845 */ function user_load($uid, $reset = FALSE) { + @trigger_error('user_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\user\Entity\User::load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); if ($reset) { \Drupal::entityManager()->getStorage('user')->resetCache([$uid]); } @@ -409,7 +408,7 @@ foreach (Element::children($build['user_picture']) as $key) { $item = $build['user_picture'][$key]['#item']; if (!$item->get('alt')->getValue()) { - $item->get('alt')->setValue(\Drupal::translation()->translate('Profile picture for user @username', ['@username' => $account->getUsername()])); + $item->get('alt')->setValue(\Drupal::translation()->translate('Profile picture for user @username', ['@username' => $account->getAccountName()])); } } } @@ -492,7 +491,7 @@ // their own shortening logic or add markup. If they do so, they must ensure // that $variables['name'] is safe for printing. $name = $account->getDisplayName(); - $variables['name_raw'] = $account->getUsername(); + $variables['name_raw'] = $account->getAccountName(); if (mb_strlen($name) > 20) { $name = Unicode::truncate($name, 15, FALSE, TRUE); $variables['truncated'] = TRUE; @@ -501,7 +500,12 @@ $variables['truncated'] = FALSE; } $variables['name'] = $name; - $variables['profile_access'] = \Drupal::currentUser()->hasPermission('access user profiles'); + if ($account instanceof AccessibleInterface) { + $variables['profile_access'] = $account->access('view'); + } + else { + $variables['profile_access'] = \Drupal::currentUser()->hasPermission('access user profiles'); + } $external = FALSE; // Populate link path and attributes if appropriate. @@ -549,7 +553,7 @@ */ function user_login_finalize(UserInterface $account) { \Drupal::currentUser()->setAccount($account); - \Drupal::logger('user')->notice('Session opened for %name.', ['%name' => $account->getUsername()]); + \Drupal::logger('user')->notice('Session opened for %name.', ['%name' => $account->getAccountName()]); // Update the user table timestamp noting user has logged in. // This is also used to invalidate one-time login links. $account->setLastLoginTime(REQUEST_TIME); @@ -601,7 +605,7 @@ function user_pass_reset_url($account, $options = []) { $timestamp = REQUEST_TIME; $langcode = isset($options['langcode']) ? $options['langcode'] : $account->getPreferredLangcode(); - return \Drupal::url('user.reset', + return Url::fromRoute('user.reset', [ 'uid' => $account->id(), 'timestamp' => $timestamp, @@ -611,7 +615,7 @@ 'absolute' => TRUE, 'language' => \Drupal::languageManager()->getLanguage($langcode), ] - ); + )->toString(); } /** @@ -635,11 +639,11 @@ $timestamp = REQUEST_TIME; $langcode = isset($options['langcode']) ? $options['langcode'] : $account->getPreferredLangcode(); $url_options = ['absolute' => TRUE, 'language' => \Drupal::languageManager()->getLanguage($langcode)]; - return \Drupal::url('user.cancel_confirm', [ + return Url::fromRoute('user.cancel_confirm', [ 'user' => $account->id(), 'timestamp' => $timestamp, 'hashed_pass' => user_pass_rehash($account, $timestamp), - ], $url_options); + ], $url_options)->toString(); } /** @@ -974,8 +978,6 @@ } } -/*** Administrative features ***********************************************/ - /** * Retrieves the names of roles matching specified conditions. * @@ -1281,7 +1283,7 @@ 'fair' => t('Fair'), 'good' => t('Good'), 'strong' => t('Strong'), - 'username' => \Drupal::currentUser()->getUsername(), + 'username' => \Drupal::currentUser()->getAccountName(), ]; }