function hook_user_view

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.

Parameters

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

\Drupal\entity\Plugin\Core\Entity\EntityDisplay $display: The entity_display object holding the display options configured for the user components.

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

$langcode: The language code used for rendering.

See also

hook_user_view_alter()

hook_entity_view()

Related topics

1 function implements 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.

user_user_view in drupal/core/modules/user/user.module
Implements hook_user_view().

File

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

Code

function hook_user_view(\Drupal\user\UserInterface $account, \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display, $view_mode, $langcode) {

  // Only do the extra work if the component is configured to be displayed.
  // This assumes a 'mymodule_addition' extra field has been defined for the
  // user entity type in hook_field_extra_fields().
  if ($display
    ->getComponent('mymodule_addition')) {
    $account->content['mymodule_addition'] = array(
      '#markup' => mymodule_addition($account),
      '#theme' => 'mymodule_my_additional_field',
    );
  }
}