Same name and namespace in other branches
- 8.9.x core/lib/Drupal.php \Drupal::currentUser()
- 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
146 calls to Drupal::currentUser()
- AccessTest::testCreateAccess in core/
modules/ file/ tests/ src/ Kernel/ AccessTest.php - Tests create access is always denied even for user 1.
- announcements_feed_toolbar in core/
modules/ announcements_feed/ announcements_feed.module - Implements hook_toolbar().
- 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.
- BlockContentEntityReferenceSelectionTest::setUp in core/
modules/ block_content/ tests/ src/ Kernel/ BlockContentEntityReferenceSelectionTest.php
File
- core/
lib/ Drupal.php, line 304
Class
- Drupal
- Static Service Container wrapper.
Code
public static function currentUser() {
return static::getContainer()
->get('current_user');
}