7.x 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.


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

$view_mode: View mode, e.g. 'full'.

$langcode: The language code used for rendering.

See also



Related topics

4 functions implement hook_user_view()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

blog_user_view in modules/blog/blog.module
Implements hook_user_view().
profile_user_view in modules/profile/profile.module
Implements hook_user_view().
trigger_user_view in modules/trigger/trigger.module
Implements hook_user_view().
user_user_view in modules/user/user.module
Implements hook_user_view().
3 invocations of hook_user_view()
field_attach_view in modules/field/field.attach.inc
Returns a renderable array for the fields on an entity.
field_view_field in modules/field/field.module
Returns a renderable array for the value of a single field in an entity.
user_build_content in modules/user/user.module
Builds a structured array representing the profile content.


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


function hook_user_view($account, $view_mode, $langcode) {
  if (user_access('create blog content', $account)) {
    $account->content['summary']['blog'] = array(
      '#type' => 'user_profile_item',
      '#title' => t('Blog'),
      '#markup' => l(t('View recent blog entries'), "blog/{$account-&gt;<span class="php-function-or-constant property member-of-variable">uid</span>}", array(
        'attributes' => array(
          'title' => t("Read !username's latest blog entries.", array(
            '!username' => format_username($account),
      '#attributes' => array(
        'class' => array(


alamp’s picture

 * Implements hook_user_view().
function me_user_view($account, $view_mode) {
  if (me_variable_get('me_user_override')) {
    $enabled = 'enabled';
    if (!empty($account->me_disable)) {
      $enabled = 'disabled';

    $account->content['me'] = array(
      '#type' => 'markup',
      '#value' => t("'%me' aliases are $enabled for this account. Account user id is '@uid'.",
            array('%me' => _me_get_me_alias(TRUE), '@uid' => $account->uid)),
      '#weight' => 10,
tz_earl’s picture

I had to change the #value property to #markup for similarly adding content.

askibinski’s picture

See hook_ENTITY_TYPE_view in Drupal 8.