diff options
author | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-11-26 08:15:32 +0000 |
---|---|---|
committer | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-11-26 08:15:32 +0000 |
commit | 045002e25c20fe67a54b1517642d120b087b5215 (patch) | |
tree | b64ba4e501beb3d390b12b4928ab4a3a36882b85 | |
parent | f337abfa697395f2b39ac7d542e66da5538fa3f4 (diff) | |
download | brdo-045002e25c20fe67a54b1517642d120b087b5215.tar.gz brdo-045002e25c20fe67a54b1517642d120b087b5215.tar.bz2 |
#111481 by chx and pwolanin: profile categories may contain slashes, but this was not yet supported by the user object menu loader
-rw-r--r-- | modules/user/user.module | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/modules/user/user.module b/modules/user/user.module index 4e742be48..c56f92693 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1047,19 +1047,21 @@ function user_menu() { 'file' => 'user.pages.inc', ); - $items['user/%user/edit'] = array( + $items['user/%user_category/edit'] = array( 'title' => 'Edit', 'page callback' => 'user_edit', 'page arguments' => array(1), 'access callback' => 'user_edit_access', 'access arguments' => array(1), 'type' => MENU_LOCAL_TASK, + 'load arguments' => array('%map', '%index'), 'file' => 'user.pages.inc', ); - $items['user/%user/edit/account'] = array( + $items['user/%user_category/edit/account'] = array( 'title' => 'Account', 'type' => MENU_DEFAULT_LOCAL_TASK, + 'load arguments' => array('%map', '%index'), ); $empty_account = new stdClass(); @@ -1067,7 +1069,7 @@ function user_menu() { foreach ($categories as $key => $category) { // 'account' is already handled by the MENU_DEFAULT_LOCAL_TASK. if ($category['name'] != 'account') { - $items['user/%user/edit/'. $category['name']] = array( + $items['user/%user_category/edit/'. $category['name']] = array( 'title callback' => 'check_plain', 'title arguments' => array($category['title']), 'page callback' => 'user_edit', @@ -1076,6 +1078,8 @@ function user_menu() { 'access arguments' => isset($category['access arguments']) ? $category['access arguments'] : array(), 'type' => MENU_LOCAL_TASK, 'weight' => $category['weight'], + 'load arguments' => array('%map', '%index'), + 'tab_parent' => 'user/%/edit', 'file' => 'user.pages.inc', ); } @@ -1093,6 +1097,45 @@ function user_current_load($arg) { } /** + * 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)) { + $empty_account = new stdClass(); + $user_categories = _user_categories($empty_account); + } + 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 the user id of the currently logged in user. */ function user_current_to_arg($arg) { |