public static function Drupal::currentUser in Drupal 9
Same name and namespace in other branches
- 8 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
63 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 303
Class
- Drupal
- Static Service Container wrapper.
Code
public static function currentUser() {
return static::getContainer()
->get('current_user');
}