Get field data from user object in Drupal 8

Public

Get data from user object when loaded

Get raw version
php
  1. // Load the current user.
  2. $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
  3.  
  4. // get field data from that user
  5. $website = $user->get('field_website')->value;
  6. $body = $user->get('body')->value;
  7.  
  8. // some default getters include
  9. $email = $user->get('mail')->value;
  10. $name = $user->get('name')->value;
  11. $uid= $user->get('uid')->value;