diff options
Diffstat (limited to 'modules/user')
-rw-r--r-- | modules/user/user.api.php | 32 | ||||
-rw-r--r-- | modules/user/user.module | 24 |
2 files changed, 46 insertions, 10 deletions
diff --git a/modules/user/user.api.php b/modules/user/user.api.php index c1e04ad53..40be80bdc 100644 --- a/modules/user/user.api.php +++ b/modules/user/user.api.php @@ -314,8 +314,10 @@ function hook_user_logout($account) { * * @param $account * The user object on which the operation is being performed. + * @param $build_mode + * Build mode, e.g. 'full'. */ -function hook_user_view($account) { +function hook_user_view($account, $build_mode) { if (user_access('create blog content', $account)) { $account->content['summary']['blog'] = array( '#type' => 'user_profile_item', @@ -327,6 +329,34 @@ function hook_user_view($account) { } /** + * The user was built; the module may modify the structured content. + * + * This hook is called after the content has been assembled in a structured array + * and may be used for doing processing which requires that the complete user + * content structure has been built. + * + * If the module wishes to act on the rendered HTML of the user rather than the + * structured content array, it may use this hook to add a #post_render callback. + * Alternatively, it could also implement hook_preprocess_user_profile(). See + * drupal_render() and theme() documentation respectively for details. + * + * @param $build + * A renderable array representing the user. + * + * @see user_build() + */ +function hook_user_build_alter($build) { + // Check for the existence of a field added by another module. + if (isset($build['an_additional_field'])) { + // Change its weight. + $build['an_additional_field']['#weight'] = -10; + } + + // Add a #post_render callback to act on the rendered HTML of the user. + $build['#post_render'][] = 'my_module_user_post_render'; +} + +/** * Inform other modules that a user role has been added. * * Modules implementing this hook can act on the user role object when saved to diff --git a/modules/user/user.module b/modules/user/user.module index d8a60d8d3..488573709 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -2084,13 +2084,15 @@ function _user_cancel($edit, $account, $method) { * * @param $account * A user object. + * @param $build_mode + * Build mode, e.g. 'full'. * * @return * An array as expected by drupal_render(). */ -function user_build($account) { +function user_build($account, $build_mode = 'full') { // Retrieve all profile fields and attach to $account->content. - user_build_content($account); + user_build_content($account, $build_mode); $build = $account->content; // We don't need duplicate rendering info in account->content. @@ -2099,8 +2101,12 @@ function user_build($account) { $build += array( '#theme' => 'user_profile', '#account' => $account, + '#build_mode' => $build_mode, ); + // Allow modules to modify the structured user. + drupal_alter('user_build', $build); + return $build; } @@ -2109,19 +2115,19 @@ function user_build($account) { * * @param $account * A user object. - * + * @param $build_mode + * Build mode, e.g. 'full'. */ -function user_build_content($account) { +function user_build_content($account, $build_mode = 'full') { + // Remove previously built content, if exists. $account->content = array(); - $accounts = array($account->uid, $account); - field_attach_prepare_view('user', $accounts, 'full'); - // Build fields content. - $account->content += field_attach_view('user', $account); + field_attach_prepare_view('user', array($account->uid, $account), $build_mode); + $account->content += field_attach_view('user', $account, $build_mode); // Populate $account->content with a render() array. - module_invoke_all('user_view', $account); + module_invoke_all('user_view', $account, $build_mode); } /** |