As a developer, I expect hook_user_format_name_alter() to alter the name displayed in the page titles for users according to the docs for AccountInterface. However, that does not work as expected because the _title_callback in UserRouteProvider calls userTitle() on the UserController, which uses the deprecated getUsername() method to retrieve the name to display.
Changing the userTitle() method to call getDisplayName() results in no change to the default behavior of the title callback.
Comment | File | Size | Author |
---|---|---|---|
#2 | drupal-user-title-callback-use-getDisplayName-2648420-2.patch | 619 bytes | Anonymous (not verified) |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedBrian Altenhofel created an issue. See original summary.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #4
markdorisonComment #7
marcusx CreditAttribution: marcusx commentedUsed this on several occasions now. Can we have this committed?
Comment #8
larowlanWe need a test here to make sure we don't lose this functionality in the future.
\Drupal\Tests\user\Functional\UserEntityCallbacksTest::testLabelCallback has all the plumbing you need, so should just be a matter of adding
to the end.
Please upload two patches, one with just the test changes (should fail) and one with the fix.
Thanks!
Comment #9
ptmkenny CreditAttribution: ptmkenny commentedComment #10
marcvangendI'm closing this as duplicate of #2629286: Use getDisplayName() for user names consistently, because that issue seems to have more momentum behind it, contains the same fix (plus a lot of similar fixes elsewhere) and tests.