function Drupal::currentUser

Same name and namespace in other branches
  1. 11.x core/lib/Drupal.php \Drupal::currentUser()
  2. 10 core/lib/Drupal.php \Drupal::currentUser()
  3. 9 core/lib/Drupal.php \Drupal::currentUser()
  4. 8.9.x core/lib/Drupal.php \Drupal::currentUser()

Gets the current active user.

This method will return the \Drupal\Core\Session\AccountProxy object of the current user. You can use the \Drupal\user\Entity\User::load() method to load the full user entity object. For example:

$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());

Return value

\Drupal\Core\Session\AccountProxyInterface The current user account proxy.

49 calls to Drupal::currentUser()
BlockContentEntityReferenceSelectionTest::setUp in core/modules/block_content/tests/src/Kernel/BlockContentEntityReferenceSelectionTest.php
CommentFieldItemList::access in core/modules/comment/src/CommentFieldItemList.php
ContentModerationViewsExecutionHooks::viewsQuerySubstitutions in core/modules/content_moderation/src/Hook/ContentModerationViewsExecutionHooks.php
Implements hook_views_query_substitutions().
content_translation_translate_access in core/modules/content_translation/content_translation.module
Access callback for the translation overview page.
CurrentUser::__construct in core/modules/user/src/Plugin/views/argument_default/CurrentUser.php
CurrentUser constructor.

... See full list

File

core/lib/Drupal.php, line 314

Class

Drupal
Static Service Container wrapper.

Code

public static function currentUser() {
  return static::getContainer()->get('current_user');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.