i want to display a taget_id values for user in node's field but i can't print them , this is what I have done in the hook :
$node = \Drupal::routeMatch()->getParameter('node'); if ($node && $node->bundle() == 'MynodeType') { $members = $node->field_members->getValue(); $members_ids = []; $current_user = \Drupal::currentUser(); $user_id = \Drupal\user\Entity\User::load($current_user->id()); foreach ($members as $member){ $members_ids[] = $member['target_id']; echo $members_ids; // why this is not like (1,8,....)? }
$member_ids = array_map(function ($member) { return $member['target_id']; }, $node->get('members')->getValue());$members_ids = array_column($node->field_members->getValue(), 'target_id');see drupal.stackexchange.com/a/207715/47547