Commit d91848a9 authored by webchick's avatar webchick
Browse files

#368559 by moshe weitzman: Return renderable arrays from profile pages.

parent 957feb0c
...@@ -40,7 +40,7 @@ function user_theme() { ...@@ -40,7 +40,7 @@ function user_theme() {
'template' => 'user-picture', 'template' => 'user-picture',
), ),
'user_profile' => array( 'user_profile' => array(
'arguments' => array('account' => NULL), 'arguments' => array('elements' => NULL),
'template' => 'user-profile', 'template' => 'user-profile',
'file' => 'user.pages.inc', 'file' => 'user.pages.inc',
), ),
......
...@@ -148,15 +148,35 @@ function user_logout() { ...@@ -148,15 +148,35 @@ function user_logout() {
/** /**
* Menu callback; Displays a user or user profile page. * 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) { function user_view($account) {
drupal_set_title($account->name); drupal_set_title($account->name);
// Retrieve all profile fields and attach to $account->content. // Retrieve all profile fields and attach to $account->content.
user_build_content($account); 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 return drupal_get_page($build);
// to your theme directory, and edit it as instructed in that file's comments.
return theme('user_profile', $account);
} }
/** /**
...@@ -168,12 +188,14 @@ function user_view($account) { ...@@ -168,12 +188,14 @@ function user_view($account) {
* @see user-picture.tpl.php * @see user-picture.tpl.php
*/ */
function template_preprocess_user_profile(&$variables) { function template_preprocess_user_profile(&$variables) {
$account = $variables['elements']['#account'];
$variables['profile'] = array(); $variables['profile'] = array();
// Sort sections by weight // 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. // Provide keyed variables so themers can print each section independently.
foreach (element_children($variables['account']->content) as $key) { foreach (element_children($account->content) as $key) {
$variables['profile'][$key] = drupal_render($variables['account']->content[$key]); $variables['profile'][$key] = drupal_render($account->content[$key]);
} }
// Collect all profiles to make it easier to print all items at once. // Collect all profiles to make it easier to print all items at once.
$variables['user_profile'] = implode($variables['profile']); $variables['user_profile'] = implode($variables['profile']);
......
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