function Drupal::currentUser
Same name in other branches
- 9 core/lib/Drupal.php \Drupal::currentUser()
- 8.9.x core/lib/Drupal.php \Drupal::currentUser()
- 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
60 calls to Drupal::currentUser()
- BlockContentEntityReferenceSelectionTest::setUp in core/
modules/ block_content/ tests/ src/ Kernel/ BlockContentEntityReferenceSelectionTest.php - BookMultilingualTest::setCurrentLanguage in core/
modules/ book/ tests/ src/ Kernel/ BookMultilingualTest.php - Sets the current language.
- 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.
File
-
core/
lib/ Drupal.php, line 304
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.