diff options
author | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-08-16 13:07:31 +0000 |
---|---|---|
committer | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-08-16 13:07:31 +0000 |
commit | 6ecef0ee38457ec06889553ca97c43b5ffa9f637 (patch) | |
tree | aeb5ee52f6a7480a13ca2197a85fd668b2a8db28 /modules | |
parent | 5658de996ccfb77ffba848ca6cebf9e2e85ab8b4 (diff) | |
download | brdo-6ecef0ee38457ec06889553ca97c43b5ffa9f637.tar.gz brdo-6ecef0ee38457ec06889553ca97c43b5ffa9f637.tar.bz2 |
#156796 by webernet, asimmonds and pwolanin: user editing forms cleanup and fixing deletion API remainings
Diffstat (limited to 'modules')
-rw-r--r-- | modules/user/user.module | 157 |
1 files changed, 95 insertions, 62 deletions
diff --git a/modules/user/user.module b/modules/user/user.module index aa18d2364..56f0419b3 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1035,7 +1035,8 @@ function user_menu() { $items['user/%user/delete'] = array( 'title' => 'Delete', - 'page callback' => 'user_edit', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('user_confirm_delete', 1), 'access callback' => 'user_access', 'access arguments' => array('administer users'), 'type' => MENU_CALLBACK, @@ -1043,8 +1044,8 @@ function user_menu() { $items['user/%user/edit'] = array( 'title' => 'Edit', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('user_edit'), + 'page callback' => 'user_edit', + 'page arguments' => array(1), 'access callback' => 'user_edit_access', 'access arguments' => array(1), 'type' => MENU_LOCAL_TASK, @@ -1063,7 +1064,8 @@ function user_menu() { $items['user/%user/edit/'. $category['name']] = array( 'title callback' => 'check_plain', 'title arguments' => array($category['title']), - 'page arguments' => array('user_edit', 3), + 'page callback' => 'user_edit', + 'page arguments' => array(1, 3), 'type' => MENU_LOCAL_TASK, 'weight' => $category['weight'], ); @@ -1569,6 +1571,7 @@ function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) { // Account information: $form['account'] = array('#type' => 'fieldset', '#title' => t('Account information'), + '#weight' => -10, ); if (user_access('change own username') || $admin || $register) { $form['account']['name'] = array('#type' => 'textfield', @@ -1687,79 +1690,47 @@ function _user_edit_submit($uid, &$edit) { } } -function user_edit($form_state, $category = 'account') { - global $user; +/** + * Menu callback; edit a user account or one of their profile categories. + */ +function user_edit($account, $category = 'account') { + drupal_set_title(check_plain($account->name)); + return drupal_get_form('user_profile_form', $account, $category); +} - $account = user_load(array('uid' => arg(1))); - if ($account === FALSE) { - drupal_set_message(t('The account does not exist or has already been deleted.')); - drupal_goto('admin/user/user'); - } - $op = !empty($_POST['op']) ? $_POST['op'] : ''; - $edit = $op ? $_POST : (array)$account; +/** + * Form builder; edit a user account or one of their profile categories. + * + * @ingroup forms + * @see user_profile_form_validate() + * @see user_profile_form_submit(). + * @see user_edit_delete_submit(). + */ +function user_profile_form($form_state, $account, $category = 'account') { - if (arg(2) == 'delete') { - if (!empty($edit['confirm'])) { - user_delete($edit, $account->uid); - drupal_goto('admin/user/user'); - } - else { - return drupal_get_form('user_confirm_delete', $account->name, $account->uid); - } - } - else if ($op == t('Delete')) { - $destination = ''; - if (isset($_REQUEST['destination'])) { - $destination = drupal_get_destination(); - unset($_REQUEST['destination']); - } - // Note: we redirect from user/uid/edit to user/uid/delete to make the tabs disappear. - drupal_goto("user/$account->uid/delete", $destination); - } + $edit = (empty($form_state['values'])) ? (array)$account : $form_state['values']; $form = _user_forms($edit, $account, $category); $form['_category'] = array('#type' => 'value', '#value' => $category); $form['_account'] = array('#type' => 'value', '#value' => $account); $form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 30); if (user_access('administer users')) { - $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'), '#weight' => 31); + $form['delete'] = array( + '#type' => 'submit', + '#value' => t('Delete'), + '#weight' => 31, + '#submit' => array('user_edit_delete_submit'), + ); } $form['#attributes']['enctype'] = 'multipart/form-data'; - $form['#validate'][] = 'user_edit_validate'; - drupal_set_title(check_plain($account->name)); return $form; } -function user_confirm_delete($name, $uid) { - $options = array('description' => t('All submissions made by this user will be attributed to the anonymous account. This action cannot be undone.')); - - return confirm_form(array(), - t('Are you sure you want to delete the account %name?', array('%name' => $name)), - 'user/'. $uid, - $options); -} - /** - * Delete a user. - * - * @param $edit An array of submitted form values. - * @param $uid The user ID of the user to delete. + * Validation function for the user account and profile editing form. */ -function user_delete($edit, $uid) { - $account = user_load(array('uid' => $uid)); - sess_destroy_uid($uid); - _user_mail_notify('status_deleted', $account); - db_query('DELETE FROM {users} WHERE uid = %d', $uid); - db_query('DELETE FROM {users_roles} WHERE uid = %d', $uid); - db_query('DELETE FROM {authmap} WHERE uid = %d', $uid); - $variables = array('%name' => $account->name, '%email' => '<'. $account->mail .'>'); - watchdog('user', 'Deleted user: %name %email.', $variables, WATCHDOG_NOTICE); - drupal_set_message(t('%name has been deleted.', $variables)); - module_invoke_all('user', 'delete', $edit, $account); -} - -function user_edit_validate($form, &$form_state) { +function user_profile_form_validate($form, &$form_state) { user_module_invoke('validate', $form_state['values'], $form_state['values']['_account'], $form_state['values']['_category']); // Validate input to ensure that non-privileged users can't alter protected data. if ((!user_access('administer users') && array_intersect(array_keys($form_state['values']), array('uid', 'init', 'session'))) || (!user_access('administer access control') && isset($form_state['values']['roles']))) { @@ -1769,7 +1740,10 @@ function user_edit_validate($form, &$form_state) { } } -function user_edit_submit($form, &$form_state) { +/** + * Submit function for the user account and profile editing form. + */ +function user_profile_form_submit($form, &$form_state) { $account = $form_state['values']['_account']; $category = $form_state['values']['_category']; unset($form_state['values']['_account'], $form_state['values']['op'], $form_state['values']['submit'], $form_state['values']['delete'], $form_state['values']['form_token'], $form_state['values']['form_id'], $form_state['values']['_category']); @@ -1783,6 +1757,65 @@ function user_edit_submit($form, &$form_state) { return; } +/** + * Submit function for the 'Delete' button on the user edit form. + */ +function user_edit_delete_submit($form, &$form_state) { + $destination = ''; + if (isset($_REQUEST['destination'])) { + $destination = drupal_get_destination(); + unset($_REQUEST['destination']); + } + // Note: We redirect from user/uid/edit to user/uid/delete to make the tabs disappear. + $form_state['redirect'] = array("user/". $form_state['values']['_account']->uid ."/delete", $destination); +} + +/** + * Form builder; confirm form for user deletion. + * + * @ingroup forms + * @see user_confirm_delete_submit(). + */ +function user_confirm_delete(&$form_state, $account) { + + $form['_account'] = array('#type' => 'value', '#value' => $account); + + return confirm_form($form, + t('Are you sure you want to delete the account %name?', array('%name' => $account->name)), + 'user/'. $account->uid, + t('All submissions made by this user will be attributed to the anonymous account. This action cannot be undone.'), + t('Delete'), t('Cancel')); +} + +/** + * Submit function for the confirm form for user deletion. + */ +function user_confirm_delete_submit($form, &$form_state) { + user_delete($form_state['values'], $form_state['values']['_account']->uid); + if (!isset($_REQUEST['destination'])) { + $form_state['redirect'] = 'admin/user/user'; + } +} + +/** + * Delete a user. + * + * @param $edit An array of submitted form values. + * @param $uid The user ID of the user to delete. + */ +function user_delete($edit, $uid) { + $account = user_load(array('uid' => $uid)); + sess_destroy_uid($uid); + _user_mail_notify('status_deleted', $account); + db_query('DELETE FROM {users} WHERE uid = %d', $uid); + db_query('DELETE FROM {users_roles} WHERE uid = %d', $uid); + db_query('DELETE FROM {authmap} WHERE uid = %d', $uid); + $variables = array('%name' => $account->name, '%email' => '<'. $account->mail .'>'); + watchdog('user', 'Deleted user: %name %email.', $variables, WATCHDOG_NOTICE); + drupal_set_message(t('%name has been deleted.', $variables)); + module_invoke_all('user', 'delete', $edit, $account); +} + function user_view($account) { drupal_set_title(check_plain($account->name)); // Retrieve all profile fields and attach to $account->content. |