You are here

public static function Drupal::currentUser in Drupal 10

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

171 calls to Drupal::currentUser()
AccessTest::testCheckFieldAccess in core/modules/file/tests/src/Kernel/AccessTest.php
Tests file entity field access.
AccessTest::testCreateAccess in core/modules/file/tests/src/Kernel/AccessTest.php
Tests create access checks.
AccessTest::testOnlyOwnerCanDeleteUpdateFile in core/modules/file/tests/src/Kernel/AccessTest.php
Tests that only the file owner can delete or update a file.
AssertPageCacheContextsAndTagsTrait::assertCacheTags in core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php
Ensures that some cache tags are present in the current response.
authorize_access_allowed in core/authorize.php
Determines if the current user is allowed to run authorize.php.

... See full list

File

core/lib/Drupal.php, line 292

Class

Drupal
Static Service Container wrapper.

Code

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