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.

CommentFileSizeAuthor
#2 drupal-user-title-callback-use-getDisplayName-2648420-2.patch619 bytesAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

Brian Altenhofel created an issue. See original summary.

Anonymous’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markdorison’s picture

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

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.

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.

marcusx’s picture

Status: Needs review » Reviewed & tested by the community

Used this on several occasions now. Can we have this committed?

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

We 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

$this->drupalGet($this->account->toUrl());
$this->assertContains($this->account->getDisplayName(), $this->getSession()->getPage()->find('css', 'title')->getText());

to the end.

Please upload two patches, one with just the test changes (should fail) and one with the fix.

Thanks!

ptmkenny’s picture

marcvangend’s picture

Status: Needs work » Closed (duplicate)

I'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.