From f63727d1765989e424a98f8133adf4ace0157f83 Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Wed, 3 Jun 2009 07:28:28 +0000 Subject: [PATCH] - Patch #479966 by Berdir: document and fix hook_user_categories. --- modules/profile/profile.module | 13 ++++--------- modules/user/user.api.php | 13 +++++++++++++ modules/user/user.module | 27 +++++++++++---------------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/modules/profile/profile.module b/modules/profile/profile.module index 44a93a635074..dc4f69526fbb 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -244,13 +244,6 @@ function profile_user_validate(&$edit, &$user, $category = NULL) { return profile_validate_profile($edit, $category); } -/** - * Implement hook_user_categories(). - */ -function profile_user_categories($edit, $user, $category = NULL) { - return profile_categories(); -} - /** * Implement hook_user_cancel(). */ @@ -495,8 +488,10 @@ function profile_validate_profile($edit, $category) { return $edit; } - -function profile_categories() { +/** + * Implement hook_user_categories(). + */ +function profile_user_categories() { $result = db_query("SELECT DISTINCT(category) FROM {profile_field}"); $data = array(); foreach ($result as $category) { diff --git a/modules/user/user.api.php b/modules/user/user.api.php index cb8ead77be32..ae1b55464c3a 100644 --- a/modules/user/user.api.php +++ b/modules/user/user.api.php @@ -251,6 +251,19 @@ function hook_user_operations() { return $operations; } + +/** + * Retrieve a list of all user setting/information categories. + */ +function hook_user_categories() { + return array(array( + 'name' => 'account', + 'title' => t('Account settings'), + 'weight' => 1, + )); +} + + /** * @} End of "addtogroup hooks". */ diff --git a/modules/user/user.module b/modules/user/user.module index 089f121abe28..6b1675643b05 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -998,10 +998,14 @@ function user_user_submit(&$edit, &$account, $category = NULL) { } /** - * Implement hook_user_categories. + * Implement hook_user_categories(). */ -function user_user_categories($edit, $account, $category = NULL) { - return array(array('name' => 'account', 'title' => t('Account settings'), 'weight' => 1)); +function user_user_categories() { + return array(array( + 'name' => 'account', + 'title' => t('Account settings'), + 'weight' => 1, + )); } function user_login_block() { @@ -1437,8 +1441,7 @@ function user_menu() { 'load arguments' => array('%map', '%index'), ); - $empty_account = new stdClass(); - if (($categories = _user_categories($empty_account)) && (count($categories) > 1)) { + 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') { @@ -1489,8 +1492,7 @@ function user_category_load($uid, &$map, $index) { // Check that the requested category exists. $valid = FALSE; if (!isset($user_categories)) { - $empty_account = new stdClass(); - $user_categories = _user_categories($empty_account); + $user_categories = _user_categories(); } foreach ($user_categories as $category) { if ($category['name'] == $category_path) { @@ -2414,15 +2416,8 @@ function user_help($path, $arg) { /** * Retrieve a list of all user setting/information categories and sort them by weight. */ -function _user_categories($account) { - $categories = array(); - - foreach (module_implements('user_categories') as $module) { - if ($data = module_invoke($module, 'user_categories', NULL, $account, '')) { - $categories = array_merge($data, $categories); - } - } - +function _user_categories() { + $categories = module_invoke_all('user_categories'); usort($categories, '_user_sort'); return $categories; -- GitLab