I want to show the term names used in a node. My term field machine name is field_category.
$query = \Drupal::entityQuery('node');
$query->condition('status', 1);
$query->condition('type', 'content_type');
$entity_ids = $query->execute();
$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($entity_ids);
foreach ($nodes as $node) {
dpm($node);
}
dpm()
prints the following.
stdClass Object(
[__CLASS__] => Drupal\node\Entity\Node
[in_preview] =>
[values] => Array
[field_category] => Array
(
[x-default] => Array
(
[0] => Array
(
[target_id] => 4
)
[1] => Array
(
[target_id] => 2
)
)
)
How can I print the term names as term-1,term-2?