Drupal 8: How to Get Username from uid

Submitted by admin on Tue, 02/20/2018 - 22:32

$uid = \Drupal::currentUser()->id() // if you wan to get a username of the current user
$account = \Drupal\user\Entity\User::load($uid); // pass your uid
$username = $account->getUsername();

Tags