Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
On the user pages (e.g. password reset page - after click on the password reset link), the user name is displayed without format_username(). I think format_username() should alway used when a user name is shown to the user (not in the watchdog log).
In our case, we use a technical name as the user name, which is not known to the user (they login by email). We store the first- and last-name in the profile and use hook_username_alter() to set the correct name to display.
But now, the user does only see the technical name on the password reset page. This is confusing.
Proposed resolution
Use format_username().
Comments
Comment #2
weri CreditAttribution: weri at Previon Plus AG commentedComment #3
weri CreditAttribution: weri at Previon Plus AG commentedComment #4
weri CreditAttribution: weri at Previon Plus AG commentedAll user names visible for the user uses now format_username().
Comment #5
weri CreditAttribution: weri at Previon Plus AG commentedUpdated patch for core version 7.43.
Comment #6
weri CreditAttribution: weri at Previon Plus AG commentedUpdated patch for core version 7.50.
Comment #8
Rajender Rajan CreditAttribution: Rajender Rajan as a volunteer commentedUpdated patch
Comment #9
Rajender Rajan CreditAttribution: Rajender Rajan as a volunteer commentedComment #10
SwapS CreditAttribution: SwapS as a volunteer and at Tech Mahindra commented@Rajender Rajan : Good to see you in the Issue queue :)
No need to use format_username in watchdog messages . That's what
weri has mentioned in the problem statement as well.
SwapS
Comment #11
SwapS CreditAttribution: SwapS as a volunteer and at Tech Mahindra commentedComment #13
Rajender Rajan CreditAttribution: Rajender Rajan as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedThanks @ SwapS ! Re-submitting patch with all above mentioned changes.
Comment #14
Rajender Rajan CreditAttribution: Rajender Rajan as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedComment #16
stefan.r CreditAttribution: stefan.r commentedWhat does this message look like in D8?
Comment #17
SwapS CreditAttribution: SwapS as a volunteer and at Tech Mahindra commentedStefan,
Same is the case with D8. Doesn't seems to be formatting username
SwapS
Comment #18
apadernoDrupal 8 uses
User::getUsername()
, but that is already marked as deprecated for Drupal 9 (i.e. it will be removed before Drupal 9 will be available). Since\Drupal\user\UserInterface::getDisplayName()
is the suggested replacement, the same type of change should be done in Drupal 7 too.I am not sure about the need to change the message in the log: The users who can see it are probably able to see the user account already; I don't see why hiding it to them.
Comment #19
SwapS CreditAttribution: SwapS as a volunteer and at Tech Mahindra commented@kiamlaluno - Implementation not only restricted to message in the log but same is approach is followed when showing messages to User.
See below:
$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)));
SwapS
Comment #20
stefan.r CreditAttribution: stefan.r commentedPer the backport policy this ought to be solved in 8.x first :)
Comment #21
apadernoAlso the tests need to be changed. See https://api.drupal.org/api/drupal/modules%21system%21system.test/7.x, the lines before the number 1251.
The last line (1251) fails because the login button is not found.
Comment #22
apadernoI am sorry. I didn't refresh the page.
Comment #23
SwapS CreditAttribution: SwapS as a volunteer and at Tech Mahindra commentedStefan,
Created new issue for taking care of Drupal 8 part of it.
SwapS
Comment #24
stefan.r CreditAttribution: stefan.r commentedPostponing this issue on the D8 issue then.
Comment #25
stefan.r CreditAttribution: stefan.r commentedComment #26
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedThis looks like a duplicate of #1078894: The User module should use format_username() for system messages or other issues referenced therein.
On the other hand maybe there's some value in fixing the simplest cases first...
Comment #27
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commented