Skip to content

Instantly share code, notes, and snippets.

@DanLaufer
Created October 19, 2018 17:32
Show Gist options
  • Save DanLaufer/e5d74a1a7ded59c774d528ed28413a49 to your computer and use it in GitHub Desktop.
Save DanLaufer/e5d74a1a7ded59c774d528ed28413a49 to your computer and use it in GitHub Desktop.
Drupal 8 - Get user from node
$user_entity = $node->uid->entity;
$variables['author_name'] = $user_entity->get('field_display_name')->view();
$user_picture = $user_entity->get('user_picture')->getValue();
if (_user_has_picture($user_picture)) {
$target_id = $user_picture[0]['target_id'];
$variables['author_picture_uri'] = _get_user_picture_uri($target_id);
}
$variables['author_bio'] = $user_entity->get('field_bio')->view();
$variables['author_twitter'] = $user_entity->get('field_twitter_username')->value;
$variables['author_url'] = $user_entity->urlInfo()->toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment