First, thank you for this module. I like that it removes an extra field (user name) for users to remember by forcing a portion of the email, or in my case, the entire email to be the user name.

The problem I'm having is when a user clicks on the user edit form. Changing the email address here does not automatically update the user name and I think that creates a lot of confusion. If I change the administration settings to allow users to change their user name, than the user edit form displays both a user name and email address fields which add more confusion. Is there a way to force the same logic on the user edit form as in the user registration form where a change on the email results on a change to the user name based on what is returned from hook_email_registration_name()

Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sgarcia.sd@gmail.com created an issue. See original summary.

greggles’s picture

Title: Changing email in user edit form does not change the user name » Optionally chang user name when user's email is changed
Version: 7.x-1.3 » 7.x-1.x-dev
Category: Support request » Feature request

This seems like a good idea as an optional feature, so updating some metadata to reflect that.

SergFromSD’s picture

I used hook_user_presave() to update the user id when the email address is changed. Since I also have my own hook_email_registration_name() I call that hook directly.

function mymodule_user_presave(&$edit, $account, $category) {
	// only react to updates to email address
	if ((!$account->is_new) && isset($edit['mail']) && ($edit['mail'] != $account->mail)) {
		$edit['name'] = mymodule_email_registration_name($edit, $account);
	}
}
SergFromSD’s picture

Title: Optionally chang user name when user's email is changed » Optionally change user name when user's email is changed
joachim’s picture

I'm not sure that this should be optional.

The automatically-generated username is still shown around the site, as the project page says:

> This automatically generated username is still displayed name for posts, comments, etc.

So if a user registers, has an automatic username that's the local-part of their email address, and then changes their email address, then the local-part of their old email address could still be publicly shown, and that's not a good thing.

joachim’s picture

Title: Optionally change user name when user's email is changed » Update the user name when user's email is changed
Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Active » Needs review
FileSize
2.23 KB

Here's a patch that always updates the username if the email is changed.

jonathanshaw’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev

Email is not used in user name in 8.x RC5+, so this must be a 7.x issue.