Commit a4b833b6 authored by Dries's avatar Dries
Browse files

- Patch #118345 by sun | nedjo, pwolanin, webchick: DIE hook_user_form() +...

- Patch #118345 by sun | nedjo, pwolanin, webchick: DIE hook_user_form() + hook_user_register() DIE!
parent 77af1955
...@@ -374,10 +374,11 @@ function block_custom_block_save($edit, $delta) { ...@@ -374,10 +374,11 @@ function block_custom_block_save($edit, $delta) {
} }
/** /**
* Implement hook_user_form(). * Implement hook_form_FORM_ID_alter().
*/ */
function block_user_form(&$edit, $account, $category) { function block_form_user_profile_form_alter(&$form, &$form_state) {
if ($category == 'account') { if ($form['#user_category'] == 'account') {
$account = $form['#user'];
$rids = array_keys($account->roles); $rids = array_keys($account->roles);
$result = db_query("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom <> 0 AND (r.rid IN (:rids) OR r.rid IS NULL) ORDER BY b.weight, b.module", array(':rids' => $rids)); $result = db_query("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom <> 0 AND (r.rid IN (:rids) OR r.rid IS NULL) ORDER BY b.weight, b.module", array(':rids' => $rids));
$form['block'] = array( $form['block'] = array(
...@@ -400,8 +401,8 @@ function block_user_form(&$edit, $account, $category) { ...@@ -400,8 +401,8 @@ function block_user_form(&$edit, $account, $category) {
} }
} }
if (!empty($return)) { if (!isset($return)) {
return $form; $form['block']['#access'] = FALSE;
} }
} }
} }
......
...@@ -145,10 +145,11 @@ function contact_load($cid) { ...@@ -145,10 +145,11 @@ function contact_load($cid) {
} }
/** /**
* Implement hook_user_form(). * Implement hook_form_FORM_ID_alter().
*/ */
function contact_user_form(&$edit, $account, $category) { function contact_form_user_profile_form_alter(&$form, &$form_state) {
if ($category == 'account') { if ($form['#user_category'] == 'account') {
$account = $form['#user'];
$form['contact'] = array('#type' => 'fieldset', $form['contact'] = array('#type' => 'fieldset',
'#title' => t('Contact settings'), '#title' => t('Contact settings'),
'#weight' => 5, '#weight' => 5,
...@@ -156,10 +157,9 @@ function contact_user_form(&$edit, $account, $category) { ...@@ -156,10 +157,9 @@ function contact_user_form(&$edit, $account, $category) {
); );
$form['contact']['contact'] = array('#type' => 'checkbox', $form['contact']['contact'] = array('#type' => 'checkbox',
'#title' => t('Personal contact form'), '#title' => t('Personal contact form'),
'#default_value' => !empty($edit['contact']) ? $edit['contact'] : FALSE, '#default_value' => !empty($account->contact) ? $account->contact : FALSE,
'#description' => t('Allow other users to contact you via a <a href="@url">personal contact form</a> which keeps your e-mail address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.', array('@url' => url("user/$account->uid/contact"))), '#description' => t('Allow other users to contact you via a <a href="@url">personal contact form</a> which keeps your e-mail address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.', array('@url' => url("user/$account->uid/contact"))),
); );
return $form;
} }
} }
......
...@@ -224,34 +224,18 @@ function locale_locale($op = 'groups') { ...@@ -224,34 +224,18 @@ function locale_locale($op = 'groups') {
} }
/** /**
* Implement hook_user_register(). * Form builder callback to display language selection widget.
*/ *
function locale_user_register(&$edit, $account, $category) { * @ingroup forms
// If we have more then one language and either creating a user on the * @see locale_form_alter()
// admin interface or edit the user, show the language selector.
if (variable_get('language_count', 1) > 1 && user_access('administer users')) {
return locale_language_selector_form($account);
}
}
/**
* Implement hook_user_form().
*/ */
function locale_user_form(&$edit, $account, $category) { function locale_language_selector_form(&$form, &$form_state, $user) {
// If we have more then one language and either creating a user on the
// admin interface or edit the user, show the language selector.
if (variable_get('language_count', 1) > 1 && $category == 'account') {
return locale_language_selector_form($account);
}
}
function locale_language_selector_form($user) {
global $language; global $language;
$languages = language_list('enabled'); $languages = language_list('enabled');
$languages = $languages[1]; $languages = $languages[1];
// If the user is being created, we set the user language to the page language. // If the user is being created, we set the user language to the page language.
$user_preferred_language = $user ? user_preferred_language($user) : $language; $user_preferred_language = $user->uid ? user_preferred_language($user) : $language;
$names = array(); $names = array();
foreach ($languages as $langcode => $item) { foreach ($languages as $langcode => $item) {
...@@ -273,7 +257,6 @@ function locale_language_selector_form($user) { ...@@ -273,7 +257,6 @@ function locale_language_selector_form($user) {
'#options' => $names, '#options' => $names,
'#description' => ($mode == LANGUAGE_NEGOTIATION_PATH) ? t("This account's default language for e-mails, and preferred language for site presentation.") : t("This account's default language for e-mails."), '#description' => ($mode == LANGUAGE_NEGOTIATION_PATH) ? t("This account's default language for e-mails, and preferred language for site presentation.") : t("This account's default language for e-mails."),
); );
return $form;
} }
/** /**
...@@ -306,9 +289,19 @@ function locale_form_node_type_form_alter(&$form, &$form_state) { ...@@ -306,9 +289,19 @@ function locale_form_node_type_form_alter(&$form, &$form_state) {
} }
/** /**
* Implement hook_form_alter(). Adds language fields to forms. * Implement hook_form_alter().
*
* Adds language fields to forms.
*/ */
function locale_form_alter(&$form, &$form_state, $form_id) { function locale_form_alter(&$form, &$form_state, $form_id) {
// Only alter user forms if there is more than one language.
if (variable_get('language_count', 1) > 1) {
// Display language selector when either creating a user on the admin
// interface or editing a user account.
if (($form_id == 'user_register' && user_access('administer users')) || ($form_id == 'user_profile_form' && $form['#user_category'] == 'account')) {
locale_language_selector_form($form, $form_state, $form['#user']);
}
}
if (isset($form['#id']) && $form['#id'] == 'node-form') { if (isset($form['#id']) && $form['#id'] == 'node-form') {
if (isset($form['#node']->type) && variable_get('language_content_type_' . $form['#node']->type, 0)) { if (isset($form['#node']->type) && variable_get('language_content_type_' . $form['#node']->type, 0)) {
$form['language'] = array( $form['language'] = array(
......
...@@ -125,7 +125,9 @@ function _openid_user_login_form_alter(&$form, &$form_state) { ...@@ -125,7 +125,9 @@ function _openid_user_login_form_alter(&$form, &$form_state) {
} }
/** /**
* Implement hook_form_alter(). Adds OpenID login to the login forms. * Implement hook_form_alter().
*
* Adds OpenID login to the login forms.
*/ */
function openid_form_user_register_alter(&$form, &$form_state) { function openid_form_user_register_alter(&$form, &$form_state) {
if (isset($_SESSION['openid']['values'])) { if (isset($_SESSION['openid']['values'])) {
......
...@@ -209,13 +209,6 @@ function profile_block_view($delta = '') { ...@@ -209,13 +209,6 @@ function profile_block_view($delta = '') {
} }
} }
/**
* Implement hook_user_register().
*/
function profile_user_register(&$edit, $account, $category) {
return profile_form_profile($edit, $account, $category, TRUE);
}
/** /**
* Implement hook_user_update(). * Implement hook_user_update().
*/ */
...@@ -230,13 +223,6 @@ function profile_user_insert(&$edit, $account, $category) { ...@@ -230,13 +223,6 @@ function profile_user_insert(&$edit, $account, $category) {
return profile_save_profile($edit, $account, $category, TRUE); return profile_save_profile($edit, $account, $category, TRUE);
} }
/**
* Implement hook_user_form().
*/
function profile_user_form(&$edit, $account, $category) {
return profile_form_profile($edit, $account, $category);
}
/** /**
* Implement hook_user_cancel(). * Implement hook_user_cancel().
*/ */
...@@ -378,7 +364,17 @@ function _profile_form_explanation($field) { ...@@ -378,7 +364,17 @@ function _profile_form_explanation($field) {
return $output; return $output;
} }
function profile_form_profile($edit, $account, $category, $register = FALSE) { /**
* Implement hook_form_alter().
*/
function profile_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_register' || $form_id == 'user_profile_form') {
$register = ($form['#user']->uid > 0 ? FALSE : TRUE);
$form = array_merge($form, profile_form_profile($form['#user'], $form['#user_category'], $register));
}
}
function profile_form_profile($account, $category, $register = FALSE) {
$result = _profile_get_fields($category, $register); $result = _profile_get_fields($category, $register);
$weight = 1; $weight = 1;
$fields = array(); $fields = array();
...@@ -392,7 +388,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) { ...@@ -392,7 +388,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) {
case 'url': case 'url':
$fields[$category][$field->name] = array('#type' => 'textfield', $fields[$category][$field->name] = array('#type' => 'textfield',
'#title' => check_plain($field->title), '#title' => check_plain($field->title),
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '', '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '',
'#maxlength' => 255, '#maxlength' => 255,
'#description' => _profile_form_explanation($field), '#description' => _profile_form_explanation($field),
'#required' => $field->required, '#required' => $field->required,
...@@ -404,7 +400,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) { ...@@ -404,7 +400,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) {
case 'textarea': case 'textarea':
$fields[$category][$field->name] = array('#type' => 'textarea', $fields[$category][$field->name] = array('#type' => 'textarea',
'#title' => check_plain($field->title), '#title' => check_plain($field->title),
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '', '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '',
'#description' => _profile_form_explanation($field), '#description' => _profile_form_explanation($field),
'#required' => $field->required, '#required' => $field->required,
); );
...@@ -412,7 +408,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) { ...@@ -412,7 +408,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) {
case 'list': case 'list':
$fields[$category][$field->name] = array('#type' => 'textarea', $fields[$category][$field->name] = array('#type' => 'textarea',
'#title' => check_plain($field->title), '#title' => check_plain($field->title),
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '', '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '',
'#description' => _profile_form_explanation($field), '#description' => _profile_form_explanation($field),
'#required' => $field->required, '#required' => $field->required,
); );
...@@ -420,7 +416,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) { ...@@ -420,7 +416,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) {
case 'checkbox': case 'checkbox':
$fields[$category][$field->name] = array('#type' => 'checkbox', $fields[$category][$field->name] = array('#type' => 'checkbox',
'#title' => check_plain($field->title), '#title' => check_plain($field->title),
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '', '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '',
'#description' => _profile_form_explanation($field), '#description' => _profile_form_explanation($field),
'#required' => $field->required, '#required' => $field->required,
); );
...@@ -435,7 +431,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) { ...@@ -435,7 +431,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) {
} }
$fields[$category][$field->name] = array('#type' => 'select', $fields[$category][$field->name] = array('#type' => 'select',
'#title' => check_plain($field->title), '#title' => check_plain($field->title),
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '', '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '',
'#options' => $options, '#options' => $options,
'#description' => _profile_form_explanation($field), '#description' => _profile_form_explanation($field),
'#required' => $field->required, '#required' => $field->required,
...@@ -444,7 +440,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) { ...@@ -444,7 +440,7 @@ function profile_form_profile($edit, $account, $category, $register = FALSE) {
case 'date': case 'date':
$fields[$category][$field->name] = array('#type' => 'date', $fields[$category][$field->name] = array('#type' => 'date',
'#title' => check_plain($field->title), '#title' => check_plain($field->title),
'#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '', '#default_value' => isset($account->{$field->name}) ? $account->{$field->name} : '',
'#description' => _profile_form_explanation($field), '#description' => _profile_form_explanation($field),
'#required' => $field->required, '#required' => $field->required,
); );
......
...@@ -1475,25 +1475,24 @@ function system_preprocess_page(&$variables) { ...@@ -1475,25 +1475,24 @@ function system_preprocess_page(&$variables) {
} }
/** /**
* Implement hook_user_form(). * Implement hook_form_FORM_ID_alter().
*/ */
function system_user_form(&$edit, $account, $category) { function system_form_user_profile_form_alter(&$form, &$form_state) {
if ($category == 'account') { if ($form['#user_category'] == 'account') {
if (variable_get('configurable_timezones', 1)) { if (variable_get('configurable_timezones', 1)) {
system_user_timezone($edit, $form); system_user_timezone($form, $form_state);
} }
return $form; return $form;
} }
} }
/** /**
* Implement hook_user_register(). * Implement hook_form_FORM_ID_alter().
*/ */
function system_user_register(&$edit, $account, $category) { function system_form_user_register_alter(&$form, &$form_state) {
if (variable_get('configurable_timezones', 1)) { if (variable_get('configurable_timezones', 1)) {
$form = array();
if (variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT) == DRUPAL_USER_TIMEZONE_SELECT) { if (variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT) == DRUPAL_USER_TIMEZONE_SELECT) {
system_user_timezone($edit, $form); system_user_timezone($form, $form_state);
} }
else { else {
$form['account']['timezone'] = array( $form['account']['timezone'] = array(
...@@ -1518,8 +1517,11 @@ function system_user_login(&$edit, $account) { ...@@ -1518,8 +1517,11 @@ function system_user_login(&$edit, $account) {
/** /**
* Add the time zone field to the user edit and register forms. * Add the time zone field to the user edit and register forms.
*/ */
function system_user_timezone(&$edit, &$form) { function system_user_timezone(&$form, &$form_state) {
global $user; global $user;
$account = $form['#user'];
$form['timezone'] = array( $form['timezone'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Locale settings'), '#title' => t('Locale settings'),
...@@ -1529,11 +1531,11 @@ function system_user_timezone(&$edit, &$form) { ...@@ -1529,11 +1531,11 @@ function system_user_timezone(&$edit, &$form) {
$form['timezone']['timezone'] = array( $form['timezone']['timezone'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Time zone'), '#title' => t('Time zone'),
'#default_value' => $edit['timezone'] ? $edit['timezone'] : ($edit['uid'] == $user->uid ? variable_get('date_default_timezone', '') : ''), '#default_value' => isset($account->timezone) ? $account->timezone : ($account->uid == $user->uid ? variable_get('date_default_timezone', '') : ''),
'#options' => system_time_zones(($edit['uid'] != $user->uid)), '#options' => system_time_zones($account->uid != $user->uid),
'#description' => t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'), '#description' => t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'),
); );
if (!$edit['timezone'] && $edit['uid'] == $user->uid) { if (!isset($account->timezone) && $account->uid == $user->uid) {
$form['timezone']['#description'] = t('Your time zone setting will be automatically detected if possible. Please confirm the selection and click save.'); $form['timezone']['#description'] = t('Your time zone setting will be automatically detected if possible. Please confirm the selection and click save.');
$form['timezone']['timezone']['#attributes'] = array('class' => array('timezone-detect')); $form['timezone']['timezone']['#attributes'] = array('class' => array('timezone-detect'));
drupal_add_js('misc/timezone.js'); drupal_add_js('misc/timezone.js');
......
...@@ -217,38 +217,6 @@ function hook_user_categories() { ...@@ -217,38 +217,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 user account is being added.
* *
...@@ -302,37 +270,6 @@ function hook_user_logout($account) { ...@@ -302,37 +270,6 @@ function hook_user_logout($account) {
->execute(); ->execute();
} }
/**
* 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. * Modify the account before it gets saved.
* *
......
...@@ -859,17 +859,6 @@ function user_user_view($account) { ...@@ -859,17 +859,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(). * Implement hook_user_validate().
*/ */
...@@ -1810,7 +1799,12 @@ function user_pass_rehash($password, $timestamp, $login) { ...@@ -1810,7 +1799,12 @@ function user_pass_rehash($password, $timestamp, $login) {
return md5($timestamp . $password . $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(); _user_password_dynamic_validation();
$admin = user_access('administer users'); $admin = user_access('administer users');
...@@ -1819,24 +1813,29 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) { ...@@ -1819,24 +1813,29 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) {
'#title' => t('Account information'), '#title' => t('Account information'),
'#weight' => -10, '#weight' => -10,
); );
// Only show name field when: registration page; or user is editing own account and can change username; or an admin user. // Only show name field when: registration page; or user is editing own
if ($register || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || $admin) { // 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', $form['account']['name'] = array('#type' => 'textfield',
'#title' => t('Username'), '#title' => t('Username'),
'#default_value' => $edit['name'],
'#maxlength' => USERNAME_MAX_LENGTH, '#maxlength' => USERNAME_MAX_LENGTH,
'#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'), '#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'),
'#required' => TRUE, '#required' => TRUE,
'#attributes' => array('class' => array('username')), '#attributes' => array('class' => array('username')),
); );
if (!$register) {
$form['account']['name']['#default_value'] = $account->name;
}
} }
$form['account']['mail'] = array('#type' => 'textfield', $form['account']['mail'] = array('#type' => 'textfield',
'#title' => t('E-mail address'), '#title' => t('E-mail address'),
'#default_value' => $edit['mail'],
'#maxlength' => EMAIL_MAX_LENGTH, '#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.'), '#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, '#required' => TRUE,
); );
if (!$register) {
$form['account']['mail']['#default_value'] = $account->mail;
}
if (!$register) { if (!$register) {
$form['account']['pass'] = array('#type' => 'password_confirm', $form['account']['pass'] = array('#type' => 'password_confirm',
'#description' => t('To change the current user password, enter the new password in both fields.'), '#description' => t('To change the current user password, enter the new password in both fields.'),
...@@ -1855,7 +1854,7 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) { ...@@ -1855,7 +1854,7 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) {
$form['account']['status'] = array( $form['account']['status'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Status'), '#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')) '#options' => array(t('Blocked'), t('Active'))
); );
} }
...@@ -1876,11 +1875,10 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) { ...@@ -1876,11 +1875,10 @@ function user_edit_form($form, &$form_state, $uid, $edit, $register = FALSE) {
unset($roles[DRUPAL_AUTHENTICATED_RID]); unset($roles[DRUPAL_AUTHENTICATED_RID]);
if ($roles) { if ($roles) {