The Stack Overflow podcast is back! Listen to an interview with our new CEO.
1 of 3

How to load user object in Drupal 8?

I need to get $global $user object in Drupal 8 . I think i missing any namespace or use class. I did $account = \Drupal::currentUser(); in the definition of a static function getSubscribedEvents() inside a class file.

I get error on drush cr: exception [error] 'Drupal\Core\DependencyInjection\ContainerNotInitializedException' with message '\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.' in /Applications/MAMP/htdocs/drupal-8.0.x-dev/core/lib/Drupal.php:129 Stack trace:

0

/Applications/MAMP/htdocs/drupal-8.0.x-dev/core/lib/Drupal.php(247): Drupal::getContainer()

1