diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 920090f..4f5b841 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -572,41 +572,39 @@ function block_custom_block_save($edit, $delta) { * Implements hook_form_FORM_ID_alter(). */ function block_form_user_profile_form_alter(&$form, &$form_state) { - if ($form['#user_category'] == 'account') { - $account = $form['#user']; - $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)); + $account = $form['#user']; + $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)); - $blocks = array(); - foreach ($result as $block) { - $data = module_invoke($block->module, 'block_info'); - if ($data[$block->delta]['info']) { - $blocks[$block->module][$block->delta] = array( - '#type' => 'checkbox', - '#title' => check_plain($data[$block->delta]['info']), - '#default_value' => isset($account->data['block'][$block->module][$block->delta]) ? $account->data['block'][$block->module][$block->delta] : ($block->custom == 1), - ); - } - } - // Only display the fieldset if there are any personalizable blocks. - if ($blocks) { - $form['block'] = array( - '#type' => 'fieldset', - '#title' => t('Personalize blocks'), - '#description' => t('Blocks consist of content or information that complements the main content of the page. Enable or disable optional blocks using the checkboxes below.'), - '#weight' => 3, - '#collapsible' => TRUE, - '#tree' => TRUE, + $blocks = array(); + foreach ($result as $block) { + $data = module_invoke($block->module, 'block_info'); + if ($data[$block->delta]['info']) { + $blocks[$block->module][$block->delta] = array( + '#type' => 'checkbox', + '#title' => check_plain($data[$block->delta]['info']), + '#default_value' => isset($account->data['block'][$block->module][$block->delta]) ? $account->data['block'][$block->module][$block->delta] : ($block->custom == 1), ); - $form['block'] += $blocks; } } + // Only display the fieldset if there are any personalizable blocks. + if ($blocks) { + $form['block'] = array( + '#type' => 'fieldset', + '#title' => t('Personalize blocks'), + '#description' => t('Blocks consist of content or information that complements the main content of the page. Enable or disable optional blocks using the checkboxes below.'), + '#weight' => 3, + '#collapsible' => TRUE, + '#tree' => TRUE, + ); + $form['block'] += $blocks; + } } /** * Implements hook_user_presave(). */ -function block_user_presave(&$edit, $account, $category) { +function block_user_presave(&$edit, $account) { if (isset($edit['block'])) { $edit['data']['block'] = $edit['block']; } diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index eaae9c6..9388877 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -213,27 +213,25 @@ function contact_mail($key, &$message, $params) { * Add the enable personal contact form to an individual user's account page. */ function contact_form_user_profile_form_alter(&$form, &$form_state) { - if ($form['#user_category'] == 'account') { - $account = $form['#user']; - $form['contact'] = array( - '#type' => 'fieldset', - '#title' => t('Contact settings'), - '#weight' => 5, - '#collapsible' => TRUE, - ); - $form['contact']['contact'] = array( - '#type' => 'checkbox', - '#title' => t('Personal contact form'), - '#default_value' => !empty($account->data['contact']) ? $account->data['contact'] : FALSE, - '#description' => t('Allow other users to contact you via a personal contact form 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"))), - ); - } + $form['contact'] = array( + '#type' => 'fieldset', + '#title' => t('Contact settings'), + '#weight' => 5, + '#collapsible' => TRUE, + ); + $account = $form['#user']; + $form['contact']['contact'] = array( + '#type' => 'checkbox', + '#title' => t('Personal contact form'), + '#default_value' => !empty($account->data['contact']) ? $account->data['contact'] : FALSE, + '#description' => t('Allow other users to contact you via a personal contact form 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"))), + ); } /** * Implements hook_user_presave(). */ -function contact_user_presave(&$edit, $account, $category) { +function contact_user_presave(&$edit, $account) { $edit['data']['contact'] = isset($edit['contact']) ? $edit['contact'] : variable_get('contact_default_status', 1); } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 1c787e9..18cf99d 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -275,7 +275,7 @@ function language_load($langcode) { * @ingroup forms * @see locale_form_alter() */ -function locale_language_selector_form(&$form, &$form_state, $user) { +function locale_language_selector_form($user) { global $language; $languages = language_list('enabled'); $languages = $languages[1]; @@ -287,15 +287,13 @@ function locale_language_selector_form(&$form, &$form_state, $user) { foreach ($languages as $langcode => $item) { $names[$langcode] = $item->name; } + // Get language negotiation settings. + $mode = language_negotiation_get(LANGUAGE_TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_DEFAULT; $form['locale'] = array( '#type' => 'fieldset', '#title' => t('Language settings'), '#weight' => 1, - '#access' => ($form['#user_category'] == 'account' || ($form['#user_category'] == 'register' && user_access('administer users'))), ); - - // Get language negotiation settings. - $mode = language_negotiation_get(LANGUAGE_TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_DEFAULT; $form['locale']['language'] = array( '#type' => (count($names) <= 5 ? 'radios' : 'select'), '#title' => t('Language'), @@ -303,6 +301,7 @@ function locale_language_selector_form(&$form, &$form_state, $user) { '#options' => $names, '#description' => $mode ? 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; } /** @@ -340,8 +339,12 @@ function locale_form_alter(&$form, &$form_state, $form_id) { if (drupal_multilingual()) { // Display language selector when either creating a user on the admin // interface or editing a user account. - if ($form_id == 'user_register_form' || ($form_id == 'user_profile_form' && $form['#user_category'] == 'account')) { - locale_language_selector_form($form, $form_state, $form['#user']); + if ($form_id == 'user_register_form' || $form_id == 'user_profile_form') { + $selector = locale_language_selector_form($form['#user']); + if ($form_id == 'user_register_form') { + $selector['locale']['#access'] = user_access('administer users'); + } + $form += $selector; } } } diff --git a/core/modules/locale/locale.test b/core/modules/locale/locale.test index ad28164..7506242 100644 --- a/core/modules/locale/locale.test +++ b/core/modules/locale/locale.test @@ -1587,7 +1587,7 @@ class LocaleUserLanguageFunctionalTest extends DrupalWebTestCase { $path = 'user/' . $web_user->uid . '/edit'; $this->drupalGet($path); // Ensure language settings fieldset is available. - $this->assertText(t('Language settings'), t('Language settings available.')); + $this->assertText(t('Language'), t('Language selector available.')); // Ensure custom language is present. $this->assertText($name, t('Language present on form.')); // Ensure disabled language isn't present. diff --git a/core/modules/openid/openid.module b/core/modules/openid/openid.module index 2bf891a..ed02891 100644 --- a/core/modules/openid/openid.module +++ b/core/modules/openid/openid.module @@ -83,7 +83,7 @@ function openid_help($path, $arg) { /** * Implements hook_user_insert(). */ -function openid_user_insert(&$edit, $account, $category) { +function openid_user_insert(&$edit, $account) { if (!empty($edit['openid_claimed_id'])) { // The user has registered after trying to log in via OpenID. if (variable_get('user_email_verification', TRUE)) { diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index 6e137b7..07ed74f 100644 --- a/core/modules/overlay/overlay.module +++ b/core/modules/overlay/overlay.module @@ -82,30 +82,27 @@ function overlay_theme() { * Implements hook_form_FORM_ID_alter(). */ function overlay_form_user_profile_form_alter(&$form, &$form_state) { - if ($form['#user_category'] == 'account') { - $account = $form['#user']; - if (user_access('access overlay', $account)) { - $form['overlay_control'] = array( - '#type' => 'fieldset', - '#title' => t('Administrative overlay'), - '#weight' => 4, - '#collapsible' => TRUE, - ); - - $form['overlay_control']['overlay'] = array( - '#type' => 'checkbox', - '#title' => t('Use the overlay for administrative pages.'), - '#description' => t('Show administrative pages on top of the page you started from.'), - '#default_value' => isset($account->data['overlay']) ? $account->data['overlay'] : 1, - ); - } + $account = $form['#user']; + if (user_access('access overlay', $account)) { + $form['overlay_control'] = array( + '#type' => 'fieldset', + '#title' => t('Administrative overlay'), + '#weight' => 4, + '#collapsible' => TRUE, + ); + $form['overlay_control']['overlay'] = array( + '#type' => 'checkbox', + '#title' => t('Use the overlay for administrative pages.'), + '#description' => t('Show administrative pages on top of the page you started from.'), + '#default_value' => isset($account->data['overlay']) ? $account->data['overlay'] : 1, + ); } } /** * Implements hook_user_presave(). */ -function overlay_user_presave(&$edit, $account, $category) { +function overlay_user_presave(&$edit, $account) { if (isset($edit['overlay'])) { $edit['data']['overlay'] = $edit['overlay']; } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index e2e16ae..cc1a0be 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1944,12 +1944,10 @@ function system_custom_theme() { * Implements hook_form_FORM_ID_alter(). */ function system_form_user_profile_form_alter(&$form, &$form_state) { - if ($form['#user_category'] == 'account') { - if (variable_get('configurable_timezones', 1)) { - system_user_timezone($form, $form_state); - } - return $form; + if (variable_get('configurable_timezones', 1)) { + system_user_timezone($form, $form_state); } + return $form; } /** @@ -1987,7 +1985,6 @@ function system_user_timezone(&$form, &$form_state) { global $user; $account = $form['#user']; - $form['timezone'] = array( '#type' => 'fieldset', '#title' => t('Locale settings'), diff --git a/core/modules/trigger/trigger.module b/core/modules/trigger/trigger.module index 6c1f58f..c0e516f 100644 --- a/core/modules/trigger/trigger.module +++ b/core/modules/trigger/trigger.module @@ -463,8 +463,8 @@ function _trigger_normalize_user_context($type, $account) { /** * Implements hook_user_login(). */ -function trigger_user_login(&$edit, $account, $category) { - _trigger_user('user_login', $edit, $account, $category); +function trigger_user_login(&$edit, $account) { + _trigger_user('user_login', $edit, $account); } /** @@ -478,15 +478,15 @@ function trigger_user_logout($account) { /** * Implements hook_user_insert(). */ -function trigger_user_insert(&$edit, $account, $category) { - _trigger_user('user_insert', $edit, $account, $category); +function trigger_user_insert(&$edit, $account) { + _trigger_user('user_insert', $edit, $account); } /** * Implements hook_user_update(). */ -function trigger_user_update(&$edit, $account, $category) { - _trigger_user('user_update', $edit, $account, $category); +function trigger_user_update(&$edit, $account) { + _trigger_user('user_update', $edit, $account); } /** @@ -505,7 +505,7 @@ function trigger_user_cancel($edit, $account, $method) { */ function trigger_user_delete($account) { $edit = array(); - _trigger_user('user_delete', $edit, $account, NULL); + _trigger_user('user_delete', $edit, $account); } /** @@ -513,13 +513,13 @@ function trigger_user_delete($account) { */ function trigger_user_view($account) { $edit = NULL; - _trigger_user('user_view', $edit, $account, NULL); + _trigger_user('user_view', $edit, $account); } /** * Calls action functions for user triggers. */ -function _trigger_user($hook, &$edit, $account, $category = NULL) { +function _trigger_user($hook, &$edit, $account, $method = NULL) { // Keep objects for reuse so that changes actions make to objects can persist. static $objects; $aids = trigger_get_assigned_actions($hook); @@ -538,7 +538,7 @@ function _trigger_user($hook, &$edit, $account, $category = NULL) { actions_do($aid, $objects[$type], $context); } else { - actions_do($aid, $account, $context, $category); + actions_do($aid, $account, $context, $method); } } } diff --git a/core/modules/user/user-profile-category.tpl.php b/core/modules/user/user-profile-category.tpl.php deleted file mode 100644 index 8b6cd99..0000000 --- a/core/modules/user/user-profile-category.tpl.php +++ /dev/null @@ -1,35 +0,0 @@ - -
- -

- - - > - - -
diff --git a/core/modules/user/user-profile-item.tpl.php b/core/modules/user/user-profile-item.tpl.php deleted file mode 100644 index 042d43a..0000000 --- a/core/modules/user/user-profile-item.tpl.php +++ /dev/null @@ -1,26 +0,0 @@ - -> -> diff --git a/core/modules/user/user-profile.tpl.php b/core/modules/user/user-profile.tpl.php index a1611c8..24c54cd 100644 --- a/core/modules/user/user-profile.tpl.php +++ b/core/modules/user/user-profile.tpl.php @@ -11,7 +11,7 @@ * such as render($user_profile['user_picture']). Always call * render($user_profile) at the end in order to print all remaining items. If * the item is a category, it will contain all its profile items. By default, - * $user_profile['summary'] is provided, which contains data on the user's + * $user_profile['member_for'] is provided, which contains data on the user's * history. Other data can be included by modules. $user_profile['user_picture'] * is available for showing the account picture. * @@ -25,10 +25,6 @@ * field language, e.g. $account->field_example['en'], thus overriding any * language negotiation rule that was previously applied. * - * @see user-profile-category.tpl.php - * Where the html is handled for the group. - * @see user-profile-item.tpl.php - * Where the html is handled for each item in the group. * @see template_preprocess_user_profile() */ ?> diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php index 0b4f38f..8cf788c 100644 --- a/core/modules/user/user.api.php +++ b/core/modules/user/user.api.php @@ -183,29 +183,6 @@ function hook_user_operations() { } /** - * Retrieve a list of user setting or profile information categories. - * - * @return - * An array of associative arrays. Each inner array has elements: - * - "name": The internal name of the category. - * - "title": The human-readable, localized name of the category. - * - "weight": An integer specifying the category's sort ordering. - * - "access callback": Name of the access callback function to use to - * determine whether the user can edit the category. Defaults to using - * user_edit_access(). See hook_menu() for more information on access - * callbacks. - * - "access arguments": Arguments for the access callback function. Defaults - * to array(1). - */ -function hook_user_categories() { - return array(array( - 'name' => 'account', - 'title' => t('Account settings'), - 'weight' => 1, - )); -} - -/** * A user account is about to be created or updated. * * This hook is primarily intended for modules that want to store properties in @@ -217,13 +194,11 @@ function hook_user_categories() { * The array of form values submitted by the user. * @param $account * The user object on which the operation is performed. - * @param $category - * The active category of user information being edited. * * @see hook_user_insert() * @see hook_user_update() */ -function hook_user_presave(&$edit, $account, $category) { +function hook_user_presave(&$edit, $account) { // Make sure that our form value 'mymodule_foo' is stored as 'mymodule_bar'. if (isset($edit['mymodule_foo'])) { $edit['data']['my_module_foo'] = $edit['my_module_foo']; @@ -240,13 +215,11 @@ function hook_user_presave(&$edit, $account, $category) { * 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. * * @see hook_user_presave() * @see hook_user_update() */ -function hook_user_insert(&$edit, $account, $category) { +function hook_user_insert(&$edit, $account) { db_insert('mytable') ->fields(array( 'myfield' => $edit['myfield'], @@ -265,13 +238,11 @@ function hook_user_insert(&$edit, $account, $category) { * The array of form values submitted by the user. * @param $account * The user object on which the operation is performed. - * @param $category - * The active category of user information being edited. * * @see hook_user_presave() * @see hook_user_insert() */ -function hook_user_update(&$edit, $account, $category) { +function hook_user_update(&$edit, $account) { db_insert('user_changes') ->fields(array( 'uid' => $account->uid, @@ -331,17 +302,8 @@ function hook_user_view($account, $view_mode, $langcode) { '#markup' => theme('user_picture', array('account' => $account)), '#weight' => -10, ); - if (!isset($account->content['summary'])) { - $account->content['summary'] = array(); - } - $account->content['summary'] += array( - '#type' => 'user_profile_category', - '#attributes' => array('class' => array('user-member')), - '#weight' => 5, - '#title' => t('History'), - ); - $account->content['summary']['member_for'] = array( - '#type' => 'user_profile_item', + $account->content['member_for'] = array( + '#type' => 'item', '#title' => t('Member for'), '#markup' => format_interval(REQUEST_TIME - $account->created), ); diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 370427f..f7175c3 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -335,3 +335,24 @@ function user_install() { ->execute(); } } + +/** + * @addtogroup updates-7.x-to-8.x + * @{ + */ + +/** + * The 'Member for' extra field has moved one level up in the array. + */ +function user_update_8000() { + $settings = field_bundle_settings('user', 'user'); + if (isset($settings['extra_fields']['display']['summary'])) { + $settings['extra_fields']['display']['member_for'] = $settings['extra_fields']['display']['summary']; + unset($settings['extra_fields']['display']['summary']); + field_bundle_settings('user', 'user', $settings); + } +} + +/** + * @} End of "addtogroup updates-7.x-to-8.x" + */ diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 2b5952d..b22d30f 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -92,13 +92,11 @@ function user_help($path, $arg) { * @param $account * The user account object to be passed as the second parameter of the hook * function. - * @param $category - * The category of user information being acted upon. */ -function user_module_invoke($type, &$edit, $account, $category = NULL) { +function user_module_invoke($type, &$edit, $account) { foreach (module_implements('user_' . $type) as $module) { $function = $module . '_user_' . $type; - $function($edit, $account, $category); + $function($edit, $account); } } @@ -116,16 +114,6 @@ function user_theme() { 'template' => 'user-profile', 'file' => 'user.pages.inc', ), - 'user_profile_category' => array( - 'render element' => 'element', - 'template' => 'user-profile-category', - 'file' => 'user.pages.inc', - ), - 'user_profile_item' => array( - 'render element' => 'element', - 'template' => 'user-profile-item', - 'file' => 'user.pages.inc', - ), 'user_list' => array( 'variables' => array('users' => NULL, 'title' => NULL), ), @@ -239,9 +227,9 @@ function user_field_extra_fields() { ), ), 'display' => array( - 'summary' => array( - 'label' => t('History'), - 'description' => t('User module history view element.'), + 'member_for' => array( + 'label' => t('Member for'), + 'description' => t('User module \'member for\' view element.'), 'weight' => 5, ), ), @@ -379,15 +367,13 @@ function user_load_by_name($name) { * An array of fields and values to save. For example array('name' * => 'My name'). Key / value pairs added to the $edit['data'] will be * serialized and saved in the {users.data} column. - * @param $category - * (optional) The category for storing profile information in. * * @return * A fully-loaded $user object upon successful save or FALSE if the save failed. * * @todo D8: Drop $edit and fix user_save() to be consistent with others. */ -function user_save($account, $edit = array(), $category = 'account') { +function user_save($account, $edit = array()) { $transaction = db_transaction(); try { if (!empty($edit['pass'])) { @@ -425,7 +411,7 @@ function user_save($account, $edit = array(), $category = 'account') { } // Invoke hook_user_presave() for all modules. - user_module_invoke('presave', $edit, $account, $category); + user_module_invoke('presave', $edit, $account); // Invoke presave operations of Field Attach API and Entity API. Those APIs // require a fully-fledged and updated entity object. Therefore, we need to @@ -523,7 +509,7 @@ function user_save($account, $edit = array(), $category = 'account') { $edit[$key] = $value; } } - user_module_invoke('update', $edit, $account, $category); + user_module_invoke('update', $edit, $account); module_invoke_all('entity_update', $account, 'user'); } else { @@ -548,7 +534,7 @@ function user_save($account, $edit = array(), $category = 'account') { field_attach_insert('user', $account); $edit = (array) $account; - user_module_invoke('insert', $edit, $account, $category); + user_module_invoke('insert', $edit, $account); module_invoke_all('entity_insert', $account, 'user'); // Save user roles. @@ -921,19 +907,6 @@ function user_search_execute($keys = NULL, $conditions = NULL) { } /** - * Implements hook_element_info(). - */ -function user_element_info() { - $types['user_profile_category'] = array( - '#theme_wrappers' => array('user_profile_category'), - ); - $types['user_profile_item'] = array( - '#theme' => 'user_profile_item', - ); - return $types; -} - -/** * Implements hook_user_view(). */ function user_user_view($account) { @@ -941,19 +914,11 @@ function user_user_view($account) { '#markup' => theme('user_picture', array('account' => $account)), '#weight' => -10, ); - if (!isset($account->content['summary'])) { - $account->content['summary'] = array(); - } - $account->content['summary'] += array( - '#type' => 'user_profile_category', - '#attributes' => array('class' => array('user-member')), - '#weight' => 5, - '#title' => t('History'), - ); - $account->content['summary']['member_for'] = array( - '#type' => 'user_profile_item', + $account->content['member_for'] = array( + '#type' => 'item', '#title' => t('Member for'), '#markup' => format_interval(REQUEST_TIME - $account->created), + '#weight' => 5, ); } @@ -1167,49 +1132,47 @@ function user_validate_current_pass(&$form, &$form_state) { * @see user_account_form() */ function user_account_form_validate($form, &$form_state) { - if ($form['#user_category'] == 'account' || $form['#user_category'] == 'register') { - $account = $form['#user']; - // Validate new or changing username. - if (isset($form_state['values']['name'])) { - if ($error = user_validate_name($form_state['values']['name'])) { - form_set_error('name', $error); - } - elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('name', db_like($form_state['values']['name']), 'LIKE')->range(0, 1)->execute()->fetchField()) { - form_set_error('name', t('The name %name is already taken.', array('%name' => $form_state['values']['name']))); - } + $account = $form['#user']; + // Validate new or changing username. + if (isset($form_state['values']['name'])) { + if ($error = user_validate_name($form_state['values']['name'])) { + form_set_error('name', $error); } + elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('name', db_like($form_state['values']['name']), 'LIKE')->range(0, 1)->execute()->fetchField()) { + form_set_error('name', t('The name %name is already taken.', array('%name' => $form_state['values']['name']))); + } + } - // Trim whitespace from mail, to prevent confusing 'e-mail not valid' - // warnings often caused by cutting and pasting. - $mail = trim($form_state['values']['mail']); - form_set_value($form['account']['mail'], $mail, $form_state); + // Trim whitespace from mail, to prevent confusing 'e-mail not valid' + // warnings often caused by cutting and pasting. + $mail = trim($form_state['values']['mail']); + form_set_value($form['account']['mail'], $mail, $form_state); - // Validate the e-mail address, and check if it is taken by an existing user. - if ($error = user_validate_mail($form_state['values']['mail'])) { - form_set_error('mail', $error); + // Validate the e-mail address, and check if it is taken by an existing user. + if ($error = user_validate_mail($form_state['values']['mail'])) { + form_set_error('mail', $error); + } + elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('mail', db_like($form_state['values']['mail']), 'LIKE')->range(0, 1)->execute()->fetchField()) { + // Format error message dependent on whether the user is logged in or not. + if ($GLOBALS['user']->uid) { + form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => $form_state['values']['mail']))); } - elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('mail', db_like($form_state['values']['mail']), 'LIKE')->range(0, 1)->execute()->fetchField()) { - // Format error message dependent on whether the user is logged in or not. - if ($GLOBALS['user']->uid) { - form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => $form_state['values']['mail']))); - } - else { - form_set_error('mail', t('The e-mail address %email is already registered. Have you forgotten your password?', array('%email' => $form_state['values']['mail'], '@password' => url('user/password')))); - } + else { + form_set_error('mail', t('The e-mail address %email is already registered. Have you forgotten your password?', array('%email' => $form_state['values']['mail'], '@password' => url('user/password')))); } + } - // Make sure the signature isn't longer than the size of the database field. - // Signatures are disabled by default, so make sure it exists first. - if (isset($form_state['values']['signature'])) { - // Move text format for user signature into 'signature_format'. - $form_state['values']['signature_format'] = $form_state['values']['signature']['format']; - // Move text value for user signature into 'signature'. - $form_state['values']['signature'] = $form_state['values']['signature']['value']; + // Make sure the signature isn't longer than the size of the database field. + // Signatures are disabled by default, so make sure it exists first. + if (isset($form_state['values']['signature'])) { + // Move text format for user signature into 'signature_format'. + $form_state['values']['signature_format'] = $form_state['values']['signature']['format']; + // Move text value for user signature into 'signature'. + $form_state['values']['signature'] = $form_state['values']['signature']['value']; - $user_schema = drupal_get_schema('users'); - if (drupal_strlen($form_state['values']['signature']) > $user_schema['fields']['signature']['length']) { - form_set_error('signature', t('The signature is too long: it must be %max characters or less.', array('%max' => $user_schema['fields']['signature']['length']))); - } + $user_schema = drupal_get_schema('users'); + if (drupal_strlen($form_state['values']['signature']) > $user_schema['fields']['signature']['length']) { + form_set_error('signature', t('The signature is too long: it must be %max characters or less.', array('%max' => $user_schema['fields']['signature']['length']))); } } } @@ -1217,19 +1180,17 @@ function user_account_form_validate($form, &$form_state) { /** * Implements hook_user_presave(). */ -function user_user_presave(&$edit, $account, $category) { - if ($category == 'account' || $category == 'register') { - if (!empty($edit['picture_upload'])) { - $edit['picture'] = $edit['picture_upload']; - } - // Delete picture if requested, and if no replacement picture was given. - elseif (!empty($edit['picture_delete'])) { - $edit['picture'] = NULL; - } - // Prepare user roles. - if (isset($edit['roles'])) { - $edit['roles'] = array_filter($edit['roles']); - } +function user_user_presave(&$edit, $account) { + if (!empty($edit['picture_upload'])) { + $edit['picture'] = $edit['picture_upload']; + } + // Delete picture if requested, and if no replacement picture was given. + elseif (!empty($edit['picture_delete'])) { + $edit['picture'] = NULL; + } + // Prepare user roles. + if (isset($edit['roles'])) { + $edit['roles'] = array_filter($edit['roles']); } // Move account cancellation information into $user->data. @@ -1240,17 +1201,6 @@ function user_user_presave(&$edit, $account, $category) { } } -/** - * Implements hook_user_categories(). - */ -function user_user_categories() { - return array(array( - 'name' => 'account', - 'title' => t('Account settings'), - 'weight' => 1, - )); -} - function user_login_block($form) { $form['#action'] = url($_GET['q'], array('query' => drupal_get_destination())); $form['#id'] = 'user-login-form'; @@ -1734,33 +1684,6 @@ function user_menu() { 'type' => MENU_LOCAL_TASK, 'file' => 'user.pages.inc', ); - - $items['user/%user_category/edit/account'] = array( - 'title' => 'Account', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'load arguments' => array('%map', '%index'), - ); - - if (($categories = _user_categories()) && (count($categories) > 1)) { - foreach ($categories as $key => $category) { - // 'account' is already handled by the MENU_DEFAULT_LOCAL_TASK. - if ($category['name'] != 'account') { - $items['user/%user_category/edit/' . $category['name']] = array( - 'title callback' => 'check_plain', - 'title arguments' => array($category['title']), - 'page callback' => 'drupal_get_form', - 'page arguments' => array('user_profile_form', 1, 3), - 'access callback' => isset($category['access callback']) ? $category['access callback'] : 'user_edit_access', - 'access arguments' => isset($category['access arguments']) ? $category['access arguments'] : array(1), - 'type' => MENU_LOCAL_TASK, - 'weight' => $category['weight'], - 'load arguments' => array('%map', '%index'), - 'tab_parent' => 'user/%/edit', - 'file' => 'user.pages.inc', - ); - } - } - } return $items; } @@ -1879,44 +1802,6 @@ function user_uid_optional_load($uid = NULL) { } /** - * Return a user object after checking if any profile category in the path exists. - */ -function user_category_load($uid, &$map, $index) { - static $user_categories, $accounts; - - // Cache $account - this load function will get called for each profile tab. - if (!isset($accounts[$uid])) { - $accounts[$uid] = user_load($uid); - } - $valid = TRUE; - if ($account = $accounts[$uid]) { - // Since the path is like user/%/edit/category_name, the category name will - // be at a position 2 beyond the index corresponding to the % wildcard. - $category_index = $index + 2; - // Valid categories may contain slashes, and hence need to be imploded. - $category_path = implode('/', array_slice($map, $category_index)); - if ($category_path) { - // Check that the requested category exists. - $valid = FALSE; - if (!isset($user_categories)) { - $user_categories = _user_categories(); - } - foreach ($user_categories as $category) { - if ($category['name'] == $category_path) { - $valid = TRUE; - // Truncate the map array in case the category name had slashes. - $map = array_slice($map, 0, $category_index); - // Assign the imploded category name to the last map element. - $map[$category_index] = $category_path; - break; - } - } - } - } - return $valid ? $account : FALSE; -} - -/** * Returns $arg or the user ID of the current user if $arg is '%' or empty. * * @todo rethink the naming of this in Drupal 8. @@ -2461,14 +2346,10 @@ function user_view_page($account) { * * When viewing a user profile, the $page array contains: * - * - $page['content']['Profile Category']: - * Profile categories keyed by their human-readable names. - * - $page['content']['Profile Category']['profile_machine_name']: - * Profile fields keyed by their machine-readable names. * - $page['content']['user_picture']: * User's rendered picture. - * - $page['content']['summary']: - * Contains the default "History" profile data for a user. + * - $page['content']['member_for']: + * Contains the default "Member for" profile data for a user. * - $page['content']['#account']: * The user account of the profile being viewed. * @@ -3275,22 +3156,6 @@ function user_multiple_cancel_confirm_submit($form, &$form_state) { } /** - * Retrieve a list of all user setting/information categories and sort them by weight. - */ -function _user_categories() { - $categories = module_invoke_all('user_categories'); - usort($categories, '_user_sort'); - - return $categories; -} - -function _user_sort($a, $b) { - $a = (array) $a + array('weight' => 0, 'title' => ''); - $b = (array) $b + array('weight' => 0, 'title' => ''); - return $a['weight'] < $b['weight'] ? -1 : ($a['weight'] > $b['weight'] ? 1 : ($a['title'] < $b['title'] ? -1 : 1)); -} - -/** * List user administration filters that can be applied. */ function user_filters() { @@ -3676,7 +3541,6 @@ function user_register_form($form, &$form_state) { } $form['#user'] = drupal_anonymous_user(); - $form['#user_category'] = 'register'; $form['#attached']['library'][] = array('system', 'jquery.cookie'); $form['#attributes']['class'][] = 'user-info-from-cookie'; diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 02870e9..8239c53 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -198,42 +198,7 @@ function template_preprocess_user_profile(&$variables) { } /** - * Process variables for user-profile-item.tpl.php. - * - * The $variables array contains the following arguments: - * - $element - * - * @see user-profile-item.tpl.php - */ -function template_preprocess_user_profile_item(&$variables) { - $variables['title'] = $variables['element']['#title']; - $variables['value'] = $variables['element']['#markup']; - $variables['attributes'] = ''; - if (isset($variables['element']['#attributes'])) { - $variables['attributes'] = drupal_attributes($variables['element']['#attributes']); - } -} - -/** - * Process variables for user-profile-category.tpl.php. - * - * The $variables array contains the following arguments: - * - $element - * - * @see user-profile-category.tpl.php - */ -function template_preprocess_user_profile_category(&$variables) { - $variables['title'] = check_plain($variables['element']['#title']); - $variables['classes_array'][] = 'user-profile-category-' . drupal_html_class($variables['title']); - $variables['profile_items'] = $variables['element']['#children']; - $variables['attributes'] = ''; - if (isset($variables['element']['#attributes'])) { - $variables['attributes'] = drupal_attributes($variables['element']['#attributes']); - } -} - -/** - * Form builder; edit a user account or one of their profile categories. + * Form builder; edit a user account. * * @ingroup forms * @see user_account_form() @@ -242,7 +207,7 @@ function template_preprocess_user_profile_category(&$variables) { * @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) { global $user; // During initial form build, add the entity to the form state for use during @@ -258,27 +223,23 @@ function user_profile_form($form, &$form_state, $account, $category = 'account') // @todo Legacy support. Modules are encouraged to access the entity using // $form_state. Remove in Drupal 8. $form['#user'] = $account; - $form['#user_category'] = $category; - if ($category == 'account') { - user_account_form($form, $form_state); - // Attach field widgets. - field_attach_form('user', $account, $form, $form_state); - } + + user_account_form($form, $form_state); + // Attach field widgets. + field_attach_form('user', $account, $form, $form_state); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array( '#type' => 'submit', '#value' => t('Save'), ); - if ($category == 'account') { - $form['actions']['cancel'] = array( - '#type' => 'submit', - '#value' => t('Cancel account'), - '#submit' => array('user_edit_cancel_submit'), - '#access' => $account->uid > 1 && (($account->uid == $user->uid && user_access('cancel account')) || user_access('administer users')), - ); - } + $form['actions']['cancel'] = array( + '#type' => 'submit', + '#value' => t('Cancel account'), + '#submit' => array('user_edit_cancel_submit'), + '#access' => $account->uid > 1 && (($account->uid == $user->uid && user_access('cancel account')) || user_access('administer users')), + ); $form['#validate'][] = 'user_profile_form_validate'; // Add the final user profile form submit handler. @@ -299,7 +260,6 @@ function user_profile_form_validate($form, &$form_state) { */ function user_profile_form_submit($form, &$form_state) { $account = $form_state['user']; - $category = $form['#user_category']; // Remove unneeded values. form_state_values_clean($form_state); @@ -315,10 +275,10 @@ function user_profile_form_submit($form, &$form_state) { // this form by taking over all values, which appear in the form values too. $edit = array_intersect_key((array) $account, $form_state['values']); - user_save($account_unchanged, $edit, $category); + user_save($account_unchanged, $edit); $form_state['values']['uid'] = $account->uid; - if ($category == 'account' && !empty($edit['pass'])) { + if (!empty($edit['pass'])) { // Remove the password reset tag since a new password was saved. unset($_SESSION['pass_reset_'. $account->uid]); }