Commit 06fbe8e9 authored by Dries's avatar Dries

- Patch #491972 by Berdir, webchick: clean-up of user/profile related hooks and APIs.

parent a83e5605
......@@ -421,7 +421,7 @@ function block_box_save($edit, $delta) {
/**
* Implement hook_user_form().
*/
function block_user_form(&$edit, &$account, $category = NULL) {
function block_user_form(&$edit, $account, $category) {
if ($category == 'account') {
$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));
......@@ -454,7 +454,7 @@ function block_user_form(&$edit, &$account, $category = NULL) {
/**
* Implement hook_user_validate().
*/
function block_user_validate(&$edit, &$account, $category = NULL) {
function block_user_validate(&$edit, $account, $category) {
if (empty($edit['block'])) {
$edit['block'] = array();
}
......
......@@ -44,12 +44,12 @@ function blog_access($op, $node, $account) {
/**
* Implement hook_user_view().
*/
function blog_user_view(&$edit, &$user, $category) {
if (user_access('create blog content', $user)) {
$user->content['summary']['blog'] = array(
function blog_user_view($account) {
if (user_access('create blog content', $account)) {
$account->content['summary']['blog'] = array(
'#type' => 'user_profile_item',
'#title' => t('Blog'),
'#markup' => l(t('View recent blog entries'), "blog/$user->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => $user->name))))),
'#markup' => l(t('View recent blog entries'), "blog/$account->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => $account->name))))),
'#attributes' => array('class' => 'blog'),
);
}
......
......@@ -138,7 +138,7 @@ function contact_load($cid) {
/**
* Implement hook_user_form().
*/
function contact_user_form(&$edit, &$user, $category = NULL) {
function contact_user_form(&$edit, $account, $category) {
if ($category == 'account') {
$form['contact'] = array('#type' => 'fieldset',
'#title' => t('Contact settings'),
......@@ -148,7 +148,7 @@ function contact_user_form(&$edit, &$user, $category = NULL) {
$form['contact']['contact'] = array('#type' => 'checkbox',
'#title' => t('Personal contact form'),
'#default_value' => !empty($edit['contact']) ? $edit['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/$user->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;
}
......@@ -157,17 +157,10 @@ function contact_user_form(&$edit, &$user, $category = NULL) {
/**
* Implement hook_user_insert().
*/
function contact_user_insert(&$edit, &$user, $category = NULL) {
function contact_user_insert(&$edit, $account, $category) {
$edit['contact'] = variable_get('contact_default_status', 1);
}
/**
* Implement hook_user_validate().
*/
function contact_user_validate(&$edit, &$user, $category = NULL) {
return array('contact' => isset($edit['contact']) ? $edit['contact'] : FALSE);
}
/**
* Implement hook_mail().
*/
......
......@@ -212,22 +212,22 @@ function locale_locale($op = 'groups') {
/**
* Implement hook_user_register().
*/
function locale_user_register(&$edit, &$user, $category = NULL) {
function locale_user_register(&$edit, $account, $category) {
// 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 && user_access('administer users')) {
return locale_language_selector_form($user);
return locale_language_selector_form($account);
}
}
/**
* Implement hook_user_form().
*/
function locale_user_form(&$edit, &$user, $category = NULL) {
function locale_user_form(&$edit, $account, $category) {
// 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($user);
return locale_language_selector_form($account);
}
}
......
......@@ -59,7 +59,7 @@ function openid_help($path, $arg) {
/**
* Implement hook_user_insert().
*/
function openid_user_insert(&$edit, &$account, $category = NULL) {
function openid_user_insert(&$edit, $account, $category) {
if (isset($_SESSION['openid']['values'])) {
// The user has registered after trying to login via OpenID.
if (variable_get('user_email_verification', TRUE)) {
......
......@@ -205,49 +205,35 @@ function profile_block_view($delta = '') {
/**
* Implement hook_user_register().
*/
function profile_user_register(&$edit, &$user, $category = NULL) {
return profile_form_profile($edit, $user, $category, TRUE);
function profile_user_register(&$edit, $account, $category) {
return profile_form_profile($edit, $account, $category, TRUE);
}
/**
* Implement hook_user_update().
*/
function profile_user_update(&$edit, &$user, $category = NULL) {
return profile_save_profile($edit, $user, $category);
function profile_user_update(&$edit, $account, $category) {
return profile_save_profile($edit, $account, $category);
}
/**
* Implement hook_user_insert().
*/
function profile_user_insert(&$edit, &$user, $category = NULL) {
return profile_save_profile($edit, $user, $category, TRUE);
}
/**
* Implement hook_user_view().
*/
function profile_user_view(&$edit, &$user, $category = NULL) {
return profile_view_profile($user);
function profile_user_insert(&$edit, $account, $category) {
return profile_save_profile($edit, $account, $category, TRUE);
}
/**
* Implement hook_user_form().
*/
function profile_user_form(&$edit, &$user, $category = NULL) {
return profile_form_profile($edit, $user, $category);
}
/**
* Implement hook_user_validate().
*/
function profile_user_validate(&$edit, &$user, $category = NULL) {
return profile_validate_profile($edit, $category);
function profile_user_form(&$edit, $account, $category) {
return profile_form_profile($edit, $account, $category);
}
/**
* Implement hook_user_cancel().
*/
function profile_user_cancel(&$edit, &$account, $method) {
function profile_user_cancel(&$edit, $account, $method) {
switch ($method) {
case 'user_cancel_reassign':
case 'user_cancel_delete':
......@@ -270,7 +256,7 @@ function profile_user_load($users) {
}
}
function profile_save_profile(&$edit, &$user, $category, $register = FALSE) {
function profile_save_profile(&$edit, $account, $category, $register = FALSE) {
$result = _profile_get_fields($category, $register);
foreach ($result as $field) {
if (_profile_field_serialize($field->type)) {
......@@ -279,7 +265,7 @@ function profile_save_profile(&$edit, &$user, $category, $register = FALSE) {
db_merge('profile_value')
->key(array(
'fid' => $field->fid,
'uid' => $user->uid,
'uid' => $account->uid,
))
->fields(array('value' => $edit[$field->name]))
->execute();
......@@ -288,7 +274,7 @@ function profile_save_profile(&$edit, &$user, $category, $register = FALSE) {
}
}
function profile_view_field($user, $field) {
function profile_view_field($account, $field) {
// Only allow browsing of private fields for admins, if browsing is enabled,
// and if a user has permission to view profiles. Note that this check is
// necessary because a user may always see their own profile.
......@@ -296,7 +282,7 @@ function profile_view_field($user, $field) {
&& (user_access('administer users') || $field->visibility != PROFILE_PRIVATE)
&& !empty($field->page);
if (isset($user->{$field->name}) && $value = $user->{$field->name}) {
if (isset($account->{$field->name}) && $value = $account->{$field->name}) {
switch ($field->type) {
case 'textarea':
return check_markup($value);
......@@ -335,12 +321,12 @@ function profile_view_field($user, $field) {
}
}
function profile_view_profile(&$user) {
$user = user_load($user->uid);
/**
* Implement hook_user_view().
*/
function profile_user_view($account) {
// Show private fields to administrators and people viewing their own account.
if (user_access('administer users') || $GLOBALS['user']->uid == $user->uid) {
if (user_access('administer users') || $GLOBALS['user']->uid == $account->uid) {
$result = db_query('SELECT * FROM {profile_field} WHERE visibility <> :hidden ORDER BY category, weight', array(':hidden' => PROFILE_HIDDEN));
}
else {
......@@ -349,18 +335,18 @@ function profile_view_profile(&$user) {
$fields = array();
foreach ($result as $field) {
if ($value = profile_view_field($user, $field)) {
if ($value = profile_view_field($account, $field)) {
$title = ($field->type != 'checkbox') ? check_plain($field->title) : NULL;
// Create a single fieldset for each category.
if (!isset($user->content[$field->category])) {
$user->content[$field->category] = array(
if (!isset($account->content[$field->category])) {
$account->content[$field->category] = array(
'#type' => 'user_profile_category',
'#title' => $field->category,
);
}
$user->content[$field->category][$field->name] = array(
$account->content[$field->category][$field->name] = array(
'#type' => 'user_profile_item',
'#title' => $title,
'#markup' => $value,
......@@ -385,7 +371,7 @@ function _profile_form_explanation($field) {
return $output;
}
function profile_form_profile($edit, $user, $category, $register = FALSE) {
function profile_form_profile($edit, $account, $category, $register = FALSE) {
$result = _profile_get_fields($category, $register);
$weight = 1;
$fields = array();
......@@ -471,7 +457,10 @@ function _profile_update_user_fields($fields, $account) {
return $fields;
}
function profile_validate_profile($edit, $category) {
/**
* Implement hook_user_validate().
*/
function profile_user_validate(&$edit, $account, $category) {
$result = _profile_get_fields($category);
foreach ($result as $field) {
if ($edit[$field->name]) {
......
......@@ -511,19 +511,6 @@ function hook_image_toolkits() {
);
}
/**
* Perform alterations profile items before they are rendered. You may omit/add/re-sort/re-categorize, etc.
*
* @param $account
* A user object whose profile is being rendered. Profile items
* are stored in $account->content.
*/
function hook_profile_alter(&$account) {
foreach ($account->content AS $key => $field) {
// do something
}
}
/**
* Alter any aspect of email sent by Drupal. You can use this hook
* to add a common site footer to all outgoing email, add extra header
......
......@@ -1392,7 +1392,7 @@ function system_preprocess_page(&$variables) {
/**
* Implement hook_user_form().
*/
function system_user_form(&$edit, &$user, $category = NULL) {
function system_user_form(&$edit, $account, $category) {
if ($category == 'account') {
if (variable_get('configurable_timezones', 1)) {
system_user_timezone($edit, $form);
......@@ -1404,7 +1404,7 @@ function system_user_form(&$edit, &$user, $category = NULL) {
/**
* Implement hook_user_register().
*/
function system_user_register(&$edit, &$user, $category = NULL) {
function system_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) {
......@@ -1423,10 +1423,10 @@ function system_user_register(&$edit, &$user, $category = NULL) {
/**
* Implement hook_user_login().
*/
function system_user_login(&$edit, &$user, $category = NULL) {
function system_user_login(&$edit, $account) {
// If the user has a NULL time zone, notify them to set a time zone.
if (!$user->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) {
drupal_set_message(t('Please configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => url("user/$user->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));
if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) {
drupal_set_message(t('Please configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => url("user/$account->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));
}
}
......
......@@ -416,28 +416,28 @@ function _trigger_normalize_user_context($type, $account) {
/**
* trigger_user_login
*/
function trigger_user_login(&$edit, &$account, $category) {
function trigger_user_login(&$edit, $account, $category) {
_trigger_user('login', $edit, $account, $category);
}
/**
* Implement hook_user_logout().
*/
function trigger_user_logout($edit, $account) {
_trigger_user('logout', $edit, $account);
function trigger_user_logout($account) {
_trigger_user('logout', $edit = NULL, $account);
}
/**
* Implement hook_user_insert().
*/
function trigger_user_insert(&$edit, &$account, $category) {
function trigger_user_insert(&$edit, $account, $category) {
_trigger_user('insert', $edit, $account, $category);
}
/**
* Implement hook_user_update().
*/
function trigger_user_update(&$edit, &$account, $category) {
function trigger_user_update(&$edit, $account, $category) {
_trigger_user('update', $edit, $account, $category);
}
......@@ -456,8 +456,8 @@ function trigger_user_cancel($edit, $account, $method) {
/**
* Implement hook_user_view().
*/
function trigger_user_view(&$edit, &$account, $category) {
_trigger_user('view', $edit, $account, $category);
function trigger_user_view($account) {
_trigger_user('view', $edit = NULL, $account, NULL);
}
/**
......@@ -465,7 +465,7 @@ function trigger_user_view(&$edit, &$account, $category) {
*
* @TODO: Take advantage of the new API and reorganise/remove this function.
*/
function _trigger_user($op, &$edit, &$account, $category = NULL) {
function _trigger_user($op, &$edit, $account, $category = NULL) {
// Keep objects for reuse so that changes actions make to objects can persist.
static $objects;
$aids = _trigger_get_hook_aids('user', $op);
......
This diff is collapsed.
......@@ -23,10 +23,10 @@
* We cannot use module_invoke() for this, because the arguments need to
* be passed by reference.
*/
function user_module_invoke($type, &$array, &$user, $category = NULL) {
function user_module_invoke($type, &$edit, $account, $category = NULL) {
foreach (module_implements('user_' . $type) as $module) {
$function = $module . '_user_' . $type;
$function($array, $user, $category);
$function($edit, $account, $category);
}
}
......@@ -878,7 +878,7 @@ function user_elements() {
/**
* Implement hook_user_view().
*/
function user_user_view(&$edit, &$account, $category = NULL) {
function user_user_view($account) {
$account->content['user_picture'] = array(
'#markup' => theme('user_picture', $account),
'#weight' => -10,
......@@ -902,7 +902,7 @@ function user_user_view(&$edit, &$account, $category = NULL) {
/**
* Implement hook_user_form.
*/
function user_user_form(&$edit, &$account, $category = NULL) {
function user_user_form(&$edit, $account, $category) {
if ($category == 'account') {
$form_state = array();
return user_edit_form($form_state, (isset($account->uid) ? $account->uid : FALSE), $edit);
......@@ -912,7 +912,7 @@ function user_user_form(&$edit, &$account, $category = NULL) {
/**
* Implement hook_user_validate().
*/
function user_user_validate(&$edit, &$account, $category = NULL) {
function user_user_validate(&$edit, $account, $category) {
if ($category == 'account') {
$uid = isset($account->uid) ? $account->uid : FALSE;
// Validate the username when: new user account; or user is editing own account and can change username; or an admin user.
......@@ -953,7 +953,7 @@ function user_user_validate(&$edit, &$account, $category = NULL) {
/**
* Implement hook_user_submit().
*/
function user_user_submit(&$edit, &$account, $category = NULL) {
function user_user_submit(&$edit, $account, $category) {
if ($category == 'account') {
if (!empty($edit['picture_upload'])) {
$edit['picture'] = $edit['picture_upload'];
......@@ -2065,19 +2065,14 @@ function _user_cancel($edit, $account, $method) {
* @return
* A structured array containing the individual elements of the profile.
*/
function user_build_content(&$account) {
$edit = NULL;
function user_build_content($account) {
$account->content = array();
// Build fields content.
// TODO D7 : figure out where exactly this needs to go
$account->content += field_attach_view('user', $account);
user_module_invoke('view', $edit, $account);
// Allow modules to modify the fully-built profile.
drupal_alter('profile', $account);
module_invoke_all('user_view', $account);
return $account->content;
}
......
......@@ -136,7 +136,7 @@ function user_logout() {
watchdog('user', 'Session closed for %name.', array('%name' => $user->name));
module_invoke_all('user_logout', NULL, $user);
module_invoke_all('user_logout', $user);
// Destroy the current session, and reset $user to the anonymous user.
session_destroy();
......
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