Problem/Motivation
This is mostly a follow-up to #2112679: getUsername() should return the username getDisplayName() for the formatted user name where some minor consensus was reached about removing hook_user_format_name_alter(). See: https://www.drupal.org/node/2112679#comment-10356635
This comes about because we let contrib change the user name through hook_user_format_name_alter() for reasons that have a lot of down-side and not a lot of up-side, mostly inherited from the time before there were fieldable user entities.
Proposed resolution
Remove hook_user_format_name_alter() and keep the account name as something only core can touch.
Remaining tasks
- Cogitate.
- Confab.
- Consense.
- Commit.
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 2575213-user_name_alter-15.patch | 8.94 KB | andypost |
| #15 | interdiff.txt | 2.43 KB | andypost |
| #11 | remove-2575213-11.patch | 82.22 KB | nlisgo |
Comments
Comment #2
piyuesh23 commentedRemoved the module_handler service calls from core/modules/user/src/Entity/User.php & core/lib/Drupal/Core/Session/UserSession.php.
There were a few tests implementing this hook as well. Have removed them as well for now. Should be re-thinking on how to get them back in.
Comment #5
nlisgo commentedComment #6
nlisgo commentedI can't discover which commit to revert to so that this patch applies so I am going to try to manually reapply the patch.
Comment #7
nlisgo commentedWasn't too much trouble to manually re-apply. Let's see what testbot says!
Comment #10
nlisgo commentedI'm going to investigate the failing tests.
Comment #11
nlisgo commentedAddressing failing tests.
Comment #12
andypostpatch contains a lot of unrelated changes (pull fresh 8.0.x)
Comment #14
nlisgo commentedApologies. I'm on a plane now. Will try and work on it on my travels.
Comment #15
andypost#11 + removal of @see
removed too
Comment #16
nlisgo commentedThanks @andypost. I did manage to clean it up but you beat me to it. I'll unassign.
Comment #17
cilefen commentedThis hook is not deprecated. We need at least a change record.
Comment #18
subhojit777There is an issue #2572821: Fix documentation on hook_user_format_name_alter(), should we continue to put out effort there?
Comment #19
hass commentedThis case confuses me a bit. You may overlooked realname module. You are breaking it hereby isn't it?
How should a developer change the display-name of a user with tokens if we cannot alter it any longer? I'm using it together with address field module and use the firstname and lastname to generate a good display-name. Others may use individual fields, but core has no replacement for this and I guess should not have. People have different needs here.
I'm just adding a reference to a caching issue here as there seems to be an important bug in core.
Comment #20
hass commentedIf someone removes it it becomes a contrib blocker.
Comment #21
hass commentedComment #22
mile23At this point, this should be considered for 8.1.x since it's an API change. #2572821: Fix documentation on hook_user_format_name_alter() should be considered a documentation-only patch for 8.0.x.
@hass: Check out the link in the issue summary, #206 and #199. @znerol mentions that he has alternatives in mind. https://www.drupal.org/node/2112679#comment-10356635
Comment #23
hass commentedThis is 9.x now as it would otherwise break realname once 8.1 comes out. And that is not acceptable.
I cannot read any of these alternatives in the linked comment.
People only run one module for altering display-name. So, no conflict.
I have overridden autocomplete of entity references in realname D7. It sounds like a lie that it is not working. Have not yet implemented this in D8, but D7 works perfectly.
Comment #24
geerlingguy commentedNote that it seems there are a lot of gotchas with D8's
hook_user_format_name_alter(); I seem to remember things more-or-less working in D7 withhook_username_alter(), and that's just not the case with D8.It would be nice if either we deprecate quickly and offer some other reliable way to alter the username, or we lock it in and clean up edge cases (e.g. username display on the user profile page, etc.) ASAP (re: @hass' comment above about Realname module).
Comment #25
hass commentedNeed some help with the remaining test failures. Can you join, please?
Comment #26
catchIf we're going to remove it in 9.x, we need to deprecate it in 8.x first, so moving back.
Comment #27
hass commentedIf you deprecate something, what is the name of the new function that alters the display name? The feature is still required and IMPORTANT!
Comment #28
andypostSuppose the proper way to render "realname" is special ds field that build from tokens
Comment #29
hass commentedThis is how realname works, but without the alter hook I cannot change the display name. This makes this case a won't fix.
Comment #30
andypost@hass suppose realname very useful so better to refactor it into calculatable field somehow like http://cgit.drupalcode.org/drupal/tree/core/modules/text/src/TextProcess...
Comment #44
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #46
smustgrave commentedFrom what I can tell using gitlab search this isn't used much so probably could still be deprecated.
Comment #47
avpadernoThe issue summary says that allowing modules to change the username with
hook_user_format_name_alter()has a lot of down-sides and not a lot of up-sides but does not make clear which those down-sides are. At least, the issue summary should explain what those down-sides are.The documentation for the hook says it can be used to ensure user privacy in situations where
$account->getDisplayName()is too revealing. I think that could still be a use case for the hook.