From d91848a92a62ad16a3b85130c30fdb99707c14df Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Mon, 20 Apr 2009 04:41:35 +0000 Subject: [PATCH] #368559 by moshe weitzman: Return renderable arrays from profile pages. --- modules/user/user.module | 2 +- modules/user/user.pages.inc | 34 ++++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/modules/user/user.module b/modules/user/user.module index 1af5f6de995..7661c37e362 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -40,7 +40,7 @@ function user_theme() { 'template' => 'user-picture', ), 'user_profile' => array( - 'arguments' => array('account' => NULL), + 'arguments' => array('elements' => NULL), 'template' => 'user-profile', 'file' => 'user.pages.inc', ), diff --git a/modules/user/user.pages.inc b/modules/user/user.pages.inc index a4909f84601..f5d684e6bd5 100644 --- a/modules/user/user.pages.inc +++ b/modules/user/user.pages.inc @@ -148,15 +148,35 @@ 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, + ); - // 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. - return theme('user_profile', $account); + return drupal_get_page($build); } /** @@ -168,12 +188,14 @@ function user_view($account) { * @see user-picture.tpl.php */ function template_preprocess_user_profile(&$variables) { + $account = $variables['elements']['#account']; + $variables['profile'] = array(); // Sort sections by weight - uasort($variables['account']->content, 'element_sort'); + uasort($account->content, 'element_sort'); // Provide keyed variables so themers can print each section independently. - foreach (element_children($variables['account']->content) as $key) { - $variables['profile'][$key] = drupal_render($variables['account']->content[$key]); + foreach (element_children($account->content) as $key) { + $variables['profile'][$key] = drupal_render($account->content[$key]); } // Collect all profiles to make it easier to print all items at once. $variables['user_profile'] = implode($variables['profile']);