summaryrefslogtreecommitdiff
path: root/modules/user
diff options
context:
space:
mode:
Diffstat (limited to 'modules/user')
-rw-r--r--modules/user/user.api.php63
-rw-r--r--modules/user/user.module80
-rw-r--r--modules/user/user.pages.inc25
3 files changed, 40 insertions, 128 deletions
diff --git a/modules/user/user.api.php b/modules/user/user.api.php
index 88d4c0fa1..82895e182 100644
--- a/modules/user/user.api.php
+++ b/modules/user/user.api.php
@@ -218,38 +218,6 @@ function hook_user_categories() {
}
/**
- * The user account edit form is about to be displayed.
- *
- * The module should present the form elements it wishes to inject
- * into the form.
- *
- * @param &$edit
- * The array of form values submitted by the user.
- * @param $account
- * The user object on which the operation is being performed.
- * @param $category
- * The active category of user information being edited.
- * @return
- * A $form array containing the form elements to display.
- */
-function hook_user_form(&$edit, $account, $category = NULL) {
- if ($category == 'account') {
- $form['comment_settings'] = array(
- '#type' => 'fieldset',
- '#title' => t('Comment settings'),
- '#collapsible' => TRUE,
- '#weight' => 4);
- $form['comment_settings']['signature'] = array(
- '#type' => 'textarea',
- '#title' => t('Signature'),
- '#default_value' => $edit['signature'],
- '#description' => t('Your signature will be publicly displayed at the end of your comments.'));
- return $form;
- }
-}
-
-
-/**
* The user account is being added.
*
* The module should save its custom additions to the user object into the
@@ -303,37 +271,6 @@ function hook_user_logout($account) {
}
/**
- * The user account registration form is about to be displayed.
- *
- * The module should present the form elements it wishes to inject into the
- * form.
- *
- * @param &$edit
- * The array of form values submitted by the user.
- * @param $account
- * The user object on which the operation is being performed.
- * @param $category
- * The active category of user information being edited.
- * @return
- * A $form array containing the form elements to display.
- */
-function hook_user_register(&$edit, $account, $category) {
- if (variable_get('configurable_timezones', 1)) {
- $form = array();
- if (variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT) == DRUPAL_USER_TIMEZONE_SELECT) {
- system_user_timezone($edit, $form);
- }
- else {
- $form['timezone'] = array(
- '#type' => 'hidden',
- '#value' => variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT) ? '' : variable_get('date_default_timezone', ''),
- );
- }
- return $form;
- }
-}
-
-/**
* Modify the account before it gets saved.
*
* @param &$edit
diff --git a/modules/user/user.module b/modules/user/user.module
index a57965202..05605499a 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -860,17 +860,6 @@ function user_user_view($account) {
}
/**
- * Implement hook_user_form.
- */
-function user_user_form(&$edit, $account, $category) {
- if ($category == 'account') {
- $form = array();
- $form_state = array();
- return user_edit_form($form, $form_state, (isset($account->uid) ? $account->uid : FALSE), $edit);
- }
-}
-
-/**
* Implement hook_user_validate().
*/
function user_user_validate(&$edit, $account, $category) {
@@ -1810,7 +1799,12 @@ function user_pass_rehash($password, $timestamp, $login) {
return md5($timestamp . $password . $login);
}
-function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) {
+function user_edit_form(&$form, &$form_state) {
+ global $user;
+
+ $account = $form['#user'];
+ $register = ($form['#user']->uid > 0 ? FALSE : TRUE);
+
_user_password_dynamic_validation();
$admin = user_access('administer users');
@@ -1819,25 +1813,30 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) {
'#title' => t('Account information'),
'#weight' => -10,
);
- // Only show name field when: registration page; or user is editing own account and can change username; or an admin user.
- if ($register || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || $admin) {
+ // Only show name field when: registration page; or user is editing own
+ // account and can change username; or an admin user.
+ if ($register || ($user->uid == $account->uid && user_access('change own username')) || $admin) {
$form['account']['name'] = array('#type' => 'textfield',
'#title' => t('Username'),
- '#default_value' => $edit['name'],
'#maxlength' => USERNAME_MAX_LENGTH,
'#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'),
'#required' => TRUE,
'#attributes' => array('class' => array('username')),
);
+ if (!$register) {
+ $form['account']['name']['#default_value'] = $account->name;
+ }
}
$form['account']['mail'] = array('#type' => 'textfield',
'#title' => t('E-mail address'),
- '#default_value' => $edit['mail'],
'#maxlength' => EMAIL_MAX_LENGTH,
'#description' => t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'),
'#required' => TRUE,
);
if (!$register) {
+ $form['account']['mail']['#default_value'] = $account->mail;
+ }
+ if (!$register) {
$form['account']['pass'] = array('#type' => 'password_confirm',
'#description' => t('To change the current user password, enter the new password in both fields.'),
'#size' => 25,
@@ -1855,7 +1854,7 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) {
$form['account']['status'] = array(
'#type' => 'radios',
'#title' => t('Status'),
- '#default_value' => isset($edit['status']) ? $edit['status'] : 1,
+ '#default_value' => isset($account->status) ? $account->status : 1,
'#options' => array(t('Blocked'), t('Active'))
);
}
@@ -1876,11 +1875,10 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) {
unset($roles[DRUPAL_AUTHENTICATED_RID]);
if ($roles) {
- $default = empty($edit['roles']) ? array() : array_keys($edit['roles']);
$form['account']['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Roles'),
- '#default_value' => $default,
+ '#default_value' => isset($account->roles) ? array_keys($account->roles) : array(),
'#options' => $roles,
DRUPAL_AUTHENTICATED_RID => $checkbox_authenticated,
);
@@ -1897,13 +1895,13 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) {
$form['signature_settings']['signature'] = array(
'#type' => 'textarea',
'#title' => t('Signature'),
- '#default_value' => $edit['signature'],
+ '#default_value' => isset($account->signature) ? $account->signature : '',
'#description' => t('Your signature will be publicly displayed at the end of your comments.'),
);
}
// Picture/avatar:
- if (variable_get('user_pictures', 0) && !$register) {
+ if (variable_get('user_pictures', 0) && !$register && !$admin) {
$form['picture'] = array(
'#type' => 'fieldset',
'#title' => t('Picture'),
@@ -1911,15 +1909,15 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) {
);
$form['picture']['picture'] = array(
'#type' => 'value',
- '#value' => $edit['picture'],
+ '#value' => isset($account->picture) ? $account->picture : NULL,
);
$form['picture']['picture_current'] = array(
- '#markup' => theme('user_picture', (object)$edit),
+ '#markup' => theme('user_picture', $account),
);
$form['picture']['picture_delete'] = array(
'#type' => 'checkbox',
'#title' => t('Delete picture'),
- '#access' => !empty($edit['picture']->fid),
+ '#access' => !empty($account->picture->fid),
'#description' => t('Check this box to delete your current picture.'),
);
$form['picture']['picture_upload'] = array(
@@ -1931,9 +1929,6 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) {
$form['#validate'][] = 'user_profile_form_validate';
$form['#validate'][] = 'user_validate_picture';
}
- $form['#uid'] = $uid;
-
- return $form;
}
/**
@@ -3073,8 +3068,11 @@ function user_register($form, &$form_state) {
drupal_goto('user/' . $user->uid);
}
- // Start with the default user edit fields.
- $form = user_edit_form($form, $form_state, NULL, NULL, TRUE);
+ $form['#user'] = drupal_anonymous_user();
+ $form['#user_category'] = 'register';
+
+ // Start with the default user account fields.
+ user_edit_form($form, $form_state);
if ($admin) {
$form['account']['notify'] = array(
'#type' => 'checkbox',
@@ -3085,13 +3083,6 @@ function user_register($form, &$form_state) {
$form_state['redirect'] = $_GET['q'];
}
- // Create a dummy variable for pass-by-reference parameters.
- $null = NULL;
- $extra = _user_forms($null, NULL, NULL, 'register');
- if ($extra) {
- $form = array_merge_recursive($form, $extra);
- }
-
// If the "account" fieldset is the only element at the top level, its
// borders are hidden for aesthetic reasons. We do not remove the fieldset but
// preserve the form structure so that modules implementing
@@ -3111,23 +3102,6 @@ function user_register_validate($form, &$form_state) {
}
/**
- * Retrieve a list of all form elements for the specified category.
- */
-function _user_forms(&$edit, $account, $category, $hook = 'form') {
- $groups = array();
- foreach (module_implements('user_' . $hook) as $module) {
- $function = $module . '_user_' . $hook;
- if ($data = $function($edit, $account, $category)) {
- $groups = array_merge_recursive($data, $groups);
- }
- }
- uasort($groups, '_user_sort');
-
- return empty($groups) ? FALSE : $groups;
-}
-
-
-/**
* Implementation of hook_modules_installed().
*/
function user_modules_installed($modules) {
diff --git a/modules/user/user.pages.inc b/modules/user/user.pages.inc
index cfe701530..25f7401bd 100644
--- a/modules/user/user.pages.inc
+++ b/modules/user/user.pages.inc
@@ -225,19 +225,21 @@ function user_edit($account, $category = 'account') {
* @see user_profile_form_submit()
* @see user_cancel_confirm_form_submit()
*/
-function user_profile_form($form, $form_state, $account, $category = 'account') {
+function user_profile_form($form, &$form_state, $account, $category = 'account') {
global $user;
- $edit = (empty($form_state['values'])) ? (array)$account : $form_state['values'];
+ $form['#user'] = $account;
+ $form['#user_category'] = $category;
- $form = _user_forms($edit, $account, $category);
+ if ($category == 'account') {
+ user_edit_form($form, $form_state);
+ }
// Attach field widgets.
- field_attach_form('user', (object) $edit, $form, $form_state);
+ field_attach_form('user', $account, $form, $form_state);
- $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 (($account->uid == $user->uid && user_access('cancel account')) || user_access('administer users')) {
$form['cancel'] = array(
'#type' => 'submit',
@@ -257,7 +259,7 @@ function user_profile_form_validate($form, &$form_state) {
$edit = (object)$form_state['values'];
field_attach_form_validate('user', $edit, $form, $form_state);
$edit = (array)$edit;
- user_module_invoke('validate', $edit, $form_state['values']['_account'], $form_state['values']['_category']);
+ user_module_invoke('validate', $edit, $form['#user'], $form['#user_category']);
// Validate input to ensure that non-privileged users can't alter protected data.
if ((!user_access('administer users') && array_intersect(array_keys($edit), array('uid', 'init', 'session'))) || (!user_access('administer permissions') && isset($form_state['values']['roles']))) {
watchdog('security', 'Detected malicious attempt to alter protected user fields.', array(), WATCHDOG_WARNING);
@@ -270,9 +272,9 @@ function user_profile_form_validate($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']['cancel'], $form_state['values']['form_token'], $form_state['values']['form_id'], $form_state['values']['_category'], $form_state['values']['form_build_id']);
+ $account = $form['#user'];
+ $category = $form['#user_category'];
+ unset($form_state['values']['op'], $form_state['values']['submit'], $form_state['values']['cancel'], $form_state['values']['form_token'], $form_state['values']['form_id'], $form_state['values']['form_build_id']);
$edit = (object)$form_state['values'];
field_attach_submit('user', $edit, $form, $form_state);
@@ -284,7 +286,6 @@ function user_profile_form_submit($form, &$form_state) {
cache_clear_all();
drupal_set_message(t('The changes have been saved.'));
- return;
}
/**
@@ -297,7 +298,7 @@ function user_edit_cancel_submit($form, &$form_state) {
unset($_GET['destination']);
}
// Note: We redirect from user/uid/edit to user/uid/cancel to make the tabs disappear.
- $form_state['redirect'] = array("user/" . $form_state['values']['_account']->uid . "/cancel", $destination);
+ $form_state['redirect'] = array("user/" . $form['#user']->uid . "/cancel", $destination);
}
/**