1 user.api.php hook_user_view($account, $view_mode, $langcode)

The user's account information is being displayed.

The module should format its custom additions for display and add them to the $account->content array.

Note that when this hook is invoked, the changes have not yet been written to the database, because a database transaction is still in progress. The transaction is not finalized until the save operation is entirely completed and user_save() goes out of scope. You should not rely on data in the database at this time as it is not updated yet. You should also note that any write/update database queries executed from this hook are also not committed immediately. Check user_save() and db_transaction() for more info.

Parameters

$account: The user object on which the operation is being performed.

$view_mode: Display mode, e.g. 'full' or 'teaser'.

$langcode: The language code used for rendering.

See also

hook_user_view_alter()

hook_entity_view()

Related topics

File

core/modules/user/user.api.php, line 310
Hooks provided by the User module.

Code

function hook_user_view($account, $view_mode, $langcode) {
  $account->content['user_picture'] = array(
    '#markup' => theme('user_picture', array('account' => $account)),
    '#weight' => -10,
  );
  $account->content['member_for'] = array(
    '#type' => 'item',
    '#title' => t('Member for'),
    '#markup' => format_interval(REQUEST_TIME - $account->created),
  );
}