Commit 54e7ab3c authored by Steve Gerbino's avatar Steve Gerbino

* Fix for undefined reference when edit['name'] isn't initialized.

parent e7d54e0e
......@@ -65,23 +65,25 @@ function realname_registration_form_alter(&$form, $form_state, $form_id) {
* Implementation of hook_user_presave().
*/
function realname_registration_user_presave(&$edit, $account, $category) {
if ($edit['name'] == 'unset_username') {
// Generate the username based on first name and last name fields.
$first_init = drupal_substr($edit['firstname'], 0, 1);
$lastname = $edit['lastname'];
$username = strtolower($first_init . $lastname);
if(isset($edit['name'])) {
if ($edit['name'] == 'unset_username') {
// Generate the username based on first name and last name fields.
$first_init = drupal_substr($edit['firstname'], 0, 1);
$lastname = $edit['lastname'];
$username = strtolower($first_init . $lastname);
// Check if the username already exists in the database.
$result = db_query("SELECT name FROM {users} WHERE name = :username", array(':username' => $username));
// While the username is taken, append a number and increment it until our username is unique.
while ($result->rowCount()) {
static $i = 0;
$result = db_query("SELECT name FROM {users} WHERE name = :username", array(':username' => $username . ++$i));
if (!($result->rowCount())) {
$username = $username . $i;
// Check if the username already exists in the database.
$result = db_query("SELECT name FROM {users} WHERE name = :username", array(':username' => $username));
// While the username is taken, append a number and increment it until our username is unique.
while ($result->rowCount()) {
static $i = 0;
$result = db_query("SELECT name FROM {users} WHERE name = :username", array(':username' => $username . ++$i));
if (!($result->rowCount())) {
$username = $username . $i;
}
}
$edit['name'] = $username;
}
$edit['name'] = $username;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment