I am trying to get all the taxonomy terms added to a node. How would I get only the taxonomy term values that are added to a code in a mymodule_preprocess_node
hook?
Current term list:
- value1 (tid=1)
- value2 (tid=2)
- value3 (tid=3)
Node list:
- node1 has
field_category = 1
- node2 has
field_category = 3
- node3 has
field_category = 1,2,3
Here is what I tried, but cannot find a way to filter and only return the taxonomy term values that are added to a node.
// Returns entire list of values, but we want only ones added to Basic page
$term_tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('field_category');
$nodes = \Drupal::entityTypeManager()->getStorage('node');
I am trying to get all the taxonomy term values, but just the entity field values.