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!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greggles’s picture

Title: Single spaces replaced by underscores » Separate cleaning of names from unique check in email_registration_unique_username - fixingsingle spaces replaced by underscores

Thanks 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?

aadityawalawalkar’s picture

FileSize
1.92 KB

Please find the patch that handles the username clean up in a separate function.
This function replaces more than one consecutive spaces with underscore.

greggles’s picture

Status: Active » Needs review
greggles’s picture

Title: Separate cleaning of names from unique check in email_registration_unique_username - fixingsingle spaces replaced by underscores » Separate cleaning of names from unique check in email_registration_unique_username: fixing single spaces replaced by underscores
FileSize
2.95 KB

This 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)?

Status: Needs review » Needs work

The last submitted patch, 1903646_unique_separate_fixing_4.patch, failed testing.

greggles’s picture

Status: Needs work » Needs review
FileSize
2.96 KB

Thank goodness for tests :)

greggles’s picture

Version: 7.x-1.1 » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

Committed 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.

greggles’s picture

Issue summary: View changes
Status: Patch (to be ported) » Fixed

Seems like a backport isn't a priority.

If someone wants a backport, please reopen.

Status: Fixed » Closed (fixed)

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