You are here

function user_view in Drupal 8

Same name and namespace in other branches
  1. 4 modules/user.module \user_view()
  2. 5 modules/user/user.module \user_view()
  3. 6 modules/user/user.pages.inc \user_view()
  4. 7 modules/user/user.module \user_view()

Generate an array for rendering the given user.

When viewing a user profile, the $page array contains:

  • $page['content']['member_for']: Contains the default "Member for" profile data for a user.
  • $page['content']['#user']: The user account of the profile being viewed.

To theme user profiles, copy core/modules/user/templates/user.html.twig to your theme directory, and edit it as instructed in that file's comments.

Parameters

\Drupal\user\UserInterface $account: A user object.

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

string|null $langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.

Return value

array An array as expected by \Drupal\Core\Render\RendererInterface::render().

Deprecated

in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->view() instead.

See also

https://www.drupal.org/node/3033656

1 call to user_view()
UserLegacyTest::testUserView in core/modules/user/tests/src/Kernel/UserLegacyTest.php
@expectedDeprecation user_view() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->view() instead. See…
6 string references to 'user_view'
CommentCacheTagsTest::getAdditionalCacheTagsForEntity in core/modules/comment/tests/src/Functional/CommentCacheTagsTest.php
Each comment must have a comment body, which always has a text format.
CommentDefaultFormatterCacheTagsTest::testCacheTags in core/modules/comment/tests/src/Kernel/CommentDefaultFormatterCacheTagsTest.php
Tests the bubbling of cache tags.
FrontPageTest::doTestFrontPageViewCacheTags in core/modules/node/tests/src/Functional/Views/FrontPageTest.php
Tests the cache tags on the front page.
NodeCacheTagsTest::getAdditionalCacheTagsForEntity in core/modules/node/tests/src/Functional/NodeCacheTagsTest.php
Each node must have an author.
RouterTest::testMatchesWithDifferentFitOrder in core/tests/Drupal/Tests/Core/Routing/RouterTest.php
@covers ::applyFitOrder

... See full list

File

core/modules/user/user.module, line 963
Enables the user registration and login system.

Code

function user_view($account, $view_mode = 'full', $langcode = NULL) {
  @trigger_error("user_view() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \\Drupal::entityTypeManager()->getViewBuilder('user')->view() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED);
  return \Drupal::entityTypeManager()
    ->getViewBuilder('user')
    ->view($account, $view_mode, $langcode);
}