Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In the most recent release of this module, hook_email_registration_name seems to be converting any space into an underscore. From what I can tell, I think it should be replacing only where there's more than one consecutive space.
I'm using the hook this way:
function mymodule_email_registration_name($edit, $account) {
$username = $edit['profile_contact_information']['field_first_name']['und'][0]['value'] . " " . $edit['profile_contact_information']['field_last_name']['und'][0]['value'];
// This next bit just to deal with duplicates
while (db_query("SELECT COUNT(*) FROM {users} WHERE name = :name", array(':name' => $username))->fetchField()) {
$username = $username . '_';
}
return $username;
}
In earlier versions this would convert field values "First" and "Last" into username "First Last", but in the most recent version it's converting to "First_Last"
Thanks!
Comment | File | Size | Author |
---|---|---|---|
#6 | 1903646_unique_separate_fixing_6.patch | 2.96 KB | greggles |
#4 | 1903646_unique_separate_fixing_4.patch | 2.95 KB | greggles |
#2 | 1903646.patch | 1.92 KB | aadityawalawalkar |
Comments
Comment #1
gregglesThanks for pointing this out.
Yeah, this seems like http://drupalcode.org/project/email_registration.git/blob/refs/heads/7.x... which is pretty overly aggressive.
I've updated the title to reflect what I think should happen. Much of the cleanup in that function should be moved to a separate cleaner function that only occurs on names that email_registration creates itself and NOT to names provided in the hook.
What do you think? Does that match your expectations? Want to provide a patch?
Comment #2
aadityawalawalkar CreditAttribution: aadityawalawalkar commentedPlease find the patch that handles the username clean up in a separate function.
This function replaces more than one consecutive spaces with underscore.
Comment #3
gregglesComment #4
gregglesThis seems OK to me, but I think we could even make the cleanup function more optional.
How about the concept in this patch (I didn't test it)?
Comment #6
gregglesThank goodness for tests :)
Comment #7
gregglesCommitted to 7.x-1.x - http://drupalcode.org/project/email_registration.git/commit/3702dea
I'll probably make a new release with this in the not too distant future.
If anyone wants to backport that would be great.
Comment #8
gregglesSeems like a backport isn't a priority.
If someone wants a backport, please reopen.