Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.1200 diff -u -p -r1.1200 user.module --- modules/user/user.module 11 Sep 2010 06:03:12 -0000 1.1200 +++ modules/user/user.module 16 Sep 2010 11:40:51 -0000 @@ -3479,6 +3479,9 @@ function user_register_form($form, &$for $form['#attached']['library'][] = array('system', 'cookie'); $form['#attributes']['class'][] = 'user-info-from-cookie'; + // Start with the default user account fields. + user_account_form($form, $form_state); + // Attach field widgets. field_attach_form('user', $form['#user'], $form, $form_state); @@ -3494,6 +3497,7 @@ function user_register_form($form, &$for '#value' => t('Create new account'), ); + $form['#validate'][] = 'user_register_validate'; // Add the final user registration form submit handler. $form['#submit'][] = 'user_register_submit'; @@ -3501,6 +3505,13 @@ function user_register_form($form, &$for } /** + * Validation function for the user registration form. + */ +function user_register_validate($form, &$form_state) { + entity_form_field_validate('user', $form, $form_state); +} + +/** * Submit handler for the user registration form. * * This function is shared by the installation form and the normal registration form, @@ -3519,13 +3530,28 @@ function user_register_submit($form, &$f } $notify = !empty($form_state['values']['notify']); + // Remove unneeded values. form_state_values_clean($form_state); $form_state['values']['pass'] = $pass; $form_state['values']['init'] = $form_state['values']['mail']; $account = $form['#user']; - $account = user_save($account, $form_state['values']); + + // Before updating the account entity, keep an unchanged copy for use with + // user_save() later. This is necessary for modules implementing the user + // hooks to be able to react on changes by comparing the values of $account + // and $edit. + $account_unchanged = clone $account; + + entity_form_submit_build_entity('user', $account, $form, $form_state); + + // Populate $edit with the properties of $account, which have been edited on + // this form by taking over all values, which appear in the form values too. + $edit = array_intersect_key((array) $account, $form_state['values']); + + $account = user_save($account_unchanged, $edit); + // Terminate if an error occurred during user_save(). if (!$account) { drupal_set_message(t("Error saving user account."), 'error');