In a follow up of issue 2888695, wouldn't it be better to use getAccountName() instead of getDisplayName()?

We were using a hook_user_format_name_alter() in our custom code to change how the username is displayed but we couldn't login with the email address anymore since the getDisplayName() change as mentioned in the related issue. I changed this to getAccountName() and now I can login with the email address again. Or is there a reason not to use getAccountName()? I can provide a patch if needed but I just want to be sure if changing this is still correct.

Comments

rgeerolf created an issue. See original summary.

rgeerolf’s picture

Version: 8.x-2.0 » 8.x-2.x-dev
StatusFileSize
new533 bytes
rgeerolf’s picture

Issue summary: View changes
geoanders’s picture

Status: Active » Needs review

Will review, but I think getAccountName() probably makes more sense. If both cases are needed, we might need to make a configurable option to switch between the two.

geoanders’s picture

Looks like getDisplayName() does call getAccountName().

In this particular method, it's also running any user_format_name alters found. Which I think makes sense.

I would try disabling the name alter and see if it works without it first.

For reference:

public function getDisplayName() {
    $name = $this->getAccountName() ?: \Drupal::config('user.settings')->get('anonymous');
    \Drupal::moduleHandler()->alter('user_format_name', $name, $this);
    return $name;
}
public function getAccountName() {
    return $this->get('name')->value ?: '';
}

  • geoanders committed 7a1b879 on 8.x-2.x
    Issue #3285369 - Add configuration option to toggle betweem accountName...
geoanders’s picture

Added configuration item that will allow the user to select source for user email/name. By default it will use display name, but you can set it to use account name instead if need be.

See commit above or latest changes in dev branch.

geoanders’s picture

Status: Needs review » Fixed
rgeerolf’s picture

Great, works for me, thanks!

Status: Fixed » Closed (fixed)

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