diff options
Diffstat (limited to 'modules/user')
-rw-r--r-- | modules/user/user.module | 53 | ||||
-rw-r--r-- | modules/user/user.pages.inc | 38 |
2 files changed, 48 insertions, 43 deletions
diff --git a/modules/user/user.module b/modules/user/user.module index 923230804..134e0fe2c 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1371,7 +1371,7 @@ function user_menu() { 'title' => 'My account', 'title callback' => 'user_page_title', 'title arguments' => array(1), - 'page callback' => 'user_view', + 'page callback' => 'user_build', 'page arguments' => array(1), 'access callback' => 'user_view_access', 'access arguments' => array(1), @@ -1502,12 +1502,9 @@ function user_uid_optional_to_arg($arg) { } /** - * Menu item title callback - use the user name if it's not the current user. + * Menu item title callback - use the user name. */ function user_page_title($account) { - if ($account->uid == $GLOBALS['user']->uid) { - return t('My account'); - } return $account->name; } @@ -2068,23 +2065,61 @@ function _user_cancel($edit, $account, $method) { } /** - * Builds a structured array representing the profile content. + * Generate an array for rendering the given user. + * + * 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']['#account']: + * The user account of the profile being viewed. + * + * To theme user profiles, copy modules/user/user-profile.tpl.php + * to your theme directory, and edit it as instructed in that file's comments. * * @param $account * A user object. * * @return - * A structured array containing the individual elements of the profile. + * An array as expected by drupal_render(). + */ +function user_build($account) { + // Retrieve all profile fields and attach to $account->content. + user_build_content($account); + + $build = $account->content; + // We don't need duplicate rendering info in account->content. + unset($account->content); + + $build += array( + '#theme' => 'user_profile', + '#account' => $account, + ); + + return $build; +} + +/** + * Builds a structured array representing the profile content. + * + * @param $account + * A user object. + * */ 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); + // Populate $account->content with a render() array. module_invoke_all('user_view', $account); - return $account->content; } /** diff --git a/modules/user/user.pages.inc b/modules/user/user.pages.inc index 7029949b5..efb300174 100644 --- a/modules/user/user.pages.inc +++ b/modules/user/user.pages.inc @@ -160,39 +160,6 @@ function user_logout() { } /** - * Menu callback; Displays a user or user profile page. - * - * The $page['content'] array for user profile pages 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']['#account']: - * The user account of the profile being viewed. - * - * To theme user profiles, copy modules/user/user-profile.tpl.php - * to your theme directory, and edit it as instructed in that file's comments. - */ -function user_view($account) { - drupal_set_title($account->name); - // Retrieve all profile fields and attach to $account->content. - user_build_content($account); - - $build = $account->content; - $build += array( - '#theme' => 'user_profile', - '#account' => $account, - ); - - return $build; -} - -/** * Process variables for user-profile.tpl.php. * * The $variables array contains the following arguments: @@ -202,7 +169,10 @@ function user_view($account) { */ function template_preprocess_user_profile(&$variables) { $account = $variables['elements']['#account']; - $variables['user_profile'] = $account->content; + // Helpful $user_profile variable for templates. + foreach (element_children($variables['elements']) as $key) { + $variables['user_profile'][$key] = $variables['elements'][$key]; + } } /** |