function Drupal::currentUser

Same name in other branches
  1. 9 core/lib/Drupal.php \Drupal::currentUser()
  2. 10 core/lib/Drupal.php \Drupal::currentUser()
  3. 11.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

69 calls to Drupal::currentUser()
BlockContentEntityReferenceSelectionTest::setUp in core/modules/block_content/tests/src/Kernel/BlockContentEntityReferenceSelectionTest.php
book_form_node_form_alter in core/modules/book/book.module
Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
book_node_links_alter in core/modules/book/book.module
Implements hook_node_links_alter().
book_node_prepare_form in core/modules/book/book.module
Implements hook_ENTITY_TYPE_prepare_form() for node entities.
ChooseBlockController::__construct in core/modules/layout_builder/src/Controller/ChooseBlockController.php
ChooseBlockController constructor.

... See full list

File

core/lib/Drupal.php, line 263

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.