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

52 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
Checks data value access.
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 316

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.