26 Aug 2022
Method to Get Username Programmatically Drupal 8
Published On: Fri, 08/26/2022 - 19:46
There are several ways to get the user's name programmatically.
$uid = 1; // For example I have get detail of user ID 1 $account = \Drupal\user\Entity\User::load($uid); // pass your uid
Method 1
drupal_set_message($account->name->value);
Method 2
drupal_set_message($account->get("name")->value);
Method 3
drupal_set_message($account->getUsername());
Method 4
drupal_set_messageā¦