Drupal 8 Get User Values

so in drupal 8 it is a bit confusing because of what you can access but this code should get you on the right path:

    $user = \Drupal::currentUser();
    $roles = $user->getRoles();

    if (in_array('somerole', $roles) || in_array('administrator', $roles)) {
      //load the ENTITY user so have access to all fields
      $user = \Drupal\user\Entity\User::load($user->id());

      $first_name = $user->field_fname->value;
      $last_name = $user->field_last_name->value;

      if (empty($first_name)) {
        $first_name = 'User';
      }
      if (empty($last_name)) {
        $last_name = '';}
Category: