Commit 70b8337c authored by catch's avatar catch

Issue #1291100 by moshe weitzman, David_Rothstein: Remove category system from user edit and view.

parent cde51eae
......@@ -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'];
}
......
......@@ -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 <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"))),
);
}
$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 <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"))),
);
}
/**
* 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);
}
......
......@@ -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;
}
}
}
......
......@@ -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.
......
......@@ -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)) {
......
......@@ -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'];
}
......
......@@ -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'),
......
......@@ -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);
}
}
}
......
<?php
/**
* @file
* Default theme implementation to present profile categories (groups of
* profile items).
*
* Categories are defined when configuring user profile fields for the site.
* It can also be defined by modules. All profile items for a category will be
* output through the $profile_items variable.
*
* @see user-profile-item.tpl.php
* where each profile item is rendered. It is implemented as a definition
* list by default.
* @see user-profile.tpl.php
* where all items and categories are collected and printed out.
*
* Available variables:
* - $title: Category title for the group of items.
* - $profile_items: All the items for the group rendered through
* user-profile-item.tpl.php.
* - $attributes: HTML attributes. Usually renders classes.
*
* @see template_preprocess_user_profile_category()
*/
?>
<section class="<?php print $classes; ?>">
<?php if ($title): ?>
<h2><?php print $title; ?></h2>
<?php endif; ?>
<dl<?php print $attributes; ?>>
<?php print $profile_items; ?>
</dl>
</section>
<?php
/**
* @file
* Default theme implementation to present profile items (values from user
* account profile fields or modules).
*
* This template is used to loop through and render each field configured
* for the user's account. It can also be the data from modules. The output is
* grouped by categories.
*
* @see user-profile-category.tpl.php
* for the parent markup. Implemented as a definition list by default.
* @see user-profile.tpl.php
* where all items and categories are collected and printed out.
*
* Available variables:
* - $title: Field title for the profile item.
* - $value: User defined value for the profile item or data from a module.
* - $attributes: HTML attributes. Usually renders classes.
*
* @see template_preprocess_user_profile_item()
*/
?>
<dt<?php print $attributes; ?>><?php print $title; ?></dt>
<dd<?php print $attributes; ?>><?php print $value; ?></dd>
......@@ -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()
*/
?>
......
......@@ -182,29 +182,6 @@ function hook_user_operations() {
return $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.
*
......@@ -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),
);
......
......@@ -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"
*/
This diff is collapsed.
......@@ -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]);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment