Problem/Motivation

In Drupal 8.0.0 we deprecated \Drupal\Core\Session\AccountInterface::getUsername(). We didn't support @trigger_error() then.

Proposed resolution

  1. Update getUserName() calls to getAccountName().
  2. Add @trigger_error() to getUsername() implementations as per https://www.drupal.org/core/deprecation

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Comments

catch created an issue. See original summary.

didebru’s picture

StatusFileSize
new1.1 KB
drupal_set_message($this->t('Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please <a href=":logout">log out</a> and try using the link again.',
            array('%other_user' => $account->getDisplayName(), '%resetting_user' => $reset_link_user->getDisplayName(), ':logout' => $this->url('user.logout'))), 'warning');

We should exchange the url() method with the equivalent. Is it urlgenerator()?

prashant.c’s picture

Version: 8.2.x-dev » 8.3.x-dev
Status: Active » Needs review
StatusFileSize
new45.17 KB

Submitting a patch against 8.3.x version.Replaced all the instances of getUsername() with getDisplayName().

Status: Needs review » Needs work

The last submitted patch, 3: replace-username-2787871-3-8.3.x.patch, failed testing.

yogeshmpawar’s picture

StatusFileSize
new45.24 KB

I have rerolled the patch for 8.2.x version.
Replaced all the instances of getUsername() with getDisplayName().

yogeshmpawar’s picture

Status: Needs work » Needs review

The last submitted patch, 2: 2787871.patch, failed testing.

catch’s picture

Not every occurrence can be changed to getDisplayName(), some need to be changed to getAccountName()

Status: Needs review » Needs work

The last submitted patch, 5: replace_username_d8_2x-2787871-5.patch, failed testing.

yogeshmpawar’s picture

Status: Needs work » Needs review
StatusFileSize
new45.24 KB

rerolled the patch as per requirement.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

yogeshmpawar’s picture

Any Update on this issue ?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

idebr’s picture

The scope creep in #3 makes this a duplicate of #2629286: Use getDisplayName() for user names consistently

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alexpott’s picture

Issue summary: View changes
Status: Needs review » Needs work
  1. +++ b/core/modules/user/src/Controller/UserController.php
    @@ -121,7 +121,7 @@ public function resetPass(Request $request, $uid, $timestamp, $hash) {
    -            array('%other_user' => $account->getUsername(), '%resetting_user' => $reset_link_user->getUsername(), ':logout' => $this->url('user.logout'))), 'warning');
    +            array('%other_user' => $account->getDisplayName(), '%resetting_user' => $reset_link_user->getDisplayName(), ':logout' => $this->url('user.logout'))), 'warning');
    

    I'm not sure this is the correct change. You're logged in as a user and you got the password reset link for another. In both cases according to the docs we should be using getAccountName() no - because here we are dealing with log in details.

  2. +++ b/core/modules/user/src/Controller/UserController.php
    @@ -268,7 +268,7 @@ public function userPage() {
    -    return $user ? ['#markup' => $user->getUsername(), '#allowed_tags' => Xss::getHtmlTagList()] : '';
    +    return $user ? ['#markup' => $user->getAccountName(), '#allowed_tags' => Xss::getHtmlTagList()] : '';
    

    This was changed by #2746065: Profile page's title/heading does not fulfill hook_user_format_name_alter to getDisplayName() and that's right because this is displayed to all users and not login information.

alexpott’s picture

Title: The 'another account is logged' in message should use display name, not deprecated getUserName() » Properly deprecated getUserName() and use getDisplayName() and getAccountName() correctly

I've updated the issue summary to reflect the full scope of work to carry out here. Now fixing the title.

alexpott’s picture

  1. +++ b/core/modules/user/src/Form/UserPasswordForm.php
    @@ -139,7 +139,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
    +      $this->logger('user')->notice('Password reset instructions mailed to %name at %email.', array('%name' => $account->getDisplayName(), '%email' => $account->getEmail()));
    

    This should be getAccountName() - it is a log message.

  2. +++ b/core/modules/user/src/Form/UserPasswordResetForm.php
    @@ -38,12 +38,12 @@ public function getFormId() {
    -      $form['message'] = array('#markup' => $this->t('<p>This is a one-time login for %user_name and will expire on %expiration_date.</p><p>Click on this button to log in to the site and change your password.</p>', array('%user_name' => $user->getUsername(), '%expiration_date' => $expiration_date)));
    +      $form['message'] = array('#markup' => $this->t('<p>This is a one-time login for %user_name and will expire on %expiration_date.</p><p>Click on this button to log in to the site and change your password.</p>', array('%user_name' => $user->getDisplayName(), '%expiration_date' => $expiration_date)));
           $form['#title'] = $this->t('Reset password');
         }
         else {
           // No expiration for first time login.
    -      $form['message'] = array('#markup' => $this->t('<p>This is a one-time login for %user_name.</p><p>Click on this button to log in to the site and change your password.</p>', array('%user_name' => $user->getUsername())));
    +      $form['message'] = array('#markup' => $this->t('<p>This is a one-time login for %user_name.</p><p>Click on this button to log in to the site and change your password.</p>', array('%user_name' => $user->getDisplayName())));
    

    This is login details stuff - imo should getAccountName()

  3. +++ b/core/modules/user/src/Tests/UserBlocksTest.php
    @@ -67,7 +67,7 @@ function testUserLoginBlock() {
    -    $edit['name'] = $user->getUsername();
    +    $edit['name'] = $user->getDisplayName();
    

    getAccountName()

  4. hmmm... let's try converting everything to getAccountName() - since that's the no change patch and then reviewing whether getDisplayName() should be used in any of the cases.
alexpott’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#2629286: Use getDisplayName() for user names consistently

As #14 points out #2629286: Use getDisplayName() for user names consistently is prior art and actually is the single issue where all this should be fixed :( ho hum going to update that issue now. Closing a duplicate

alexpott’s picture

Issue summary: View changes
Status: Closed (duplicate) » Needs review
StatusFileSize
new135.03 KB

Thought about this some more. What we can do here is do the proper deprecation and then in #2629286: Use getDisplayName() for user names consistently do the proper usage part. This means that issue will have less to do.

alexpott’s picture

Title: Properly deprecated getUserName() and use getDisplayName() and getAccountName() correctly » Properly deprecated getUserName() and use getAccountName() instead
alexpott’s picture

Title: Properly deprecated getUserName() and use getAccountName() instead » Properly deprecate getUserName() and use getAccountName() instead
hass’s picture

Status: Needs review » Closed (duplicate)

The username/accountname/displayname conversion is already done in #2629286: Use getDisplayName() for user names consistently. Do not break all efforts, please!

alexpott’s picture

Status: Closed (duplicate) » Needs review

@hass please read and understand https://www.drupal.org/core/scope there is a reason why https://www.drupal.org/project/drupal/issues/2629286 is taking ages to get done.

alexpott’s picture

hass’s picture

We can split the AccountName/Display name out of the other patch and follow up with tests later. ONLY the tests hold the other case back and this is caused by bugs committed for several years to core. The rest of the patch is fine and all you'd like to commit here.

hass’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

alexpott’s picture

StatusFileSize
new135.13 KB

Rerolled on top of 8.7.x HEAD. There were three very minor conflicts:

Applying: Init commit
Recorded resolution for 'core/modules/system/tests/modules/session_test/session_test.module'.
Recorded resolution for 'core/modules/user/tests/src/Functional/UserBlocksTest.php'.
Recorded resolution for 'core/modules/user/user.module'.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 29: 2787871-2-28.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.37 KB
new136.5 KB

And this is why we need to do proper deprecations. Because new usages creep in.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed d8a6a68 and pushed to 8.7.x. Thanks!

  • catch committed d8a6a68 on 8.7.x
    Issue #2787871 by alexpott, yogeshmpawar, Insasse, Prashant.c, catch,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.