Constructing array of term reference labels in php template? I'm currently trying to set up a simple LMS and have already defined a content type course that contains a term reference field accesstags, which I would like to use for defining view permissions. I.e. the field accesstags will contain multiple terms that will be linked to roles that should have access to the node in question.

To make a long story short: I have created a custom module that contains the function hook_entity_view_mode_alter and I would like to check, whether the term reference field accesstags contains the term "subscription":

function hook_entity_view_mode_alter(&amp;$view_mode, Drupal\Core\Entity\EntityInterface $entity, $context) {
  ...
  if (in_array('subscription', ?????)) {
    ... allow access ...
  }
  ...
}


However, I'm not sure what to put at the spot that I marked with "?????". I know that I can construct the array of referenced terms by using $entity-&gt;get('field_accesstags')-&gt;referencedEntities()... but this array then contains the whole structure, whereas I only need the array of labels.

Is there an easy way for getting this array? Maybe even a built-in function?

Any help would be much appreciated.
Following @4k4's suggestion to post the final code as an answer myself... here's the code that I'm now using and that seems to work well...

First of all, I defined a simple helper function:

function getTermName($term) {
  return($term-&gt;getName());
}


This allowed me to extend my code (see my original question above):

function hook_entity_view_mode_alter(&amp;$view_mode, Drupal\Core\Entity\EntityInterface $entity, $context) {
  ...
  $accesstags = array_map("getTermName", $entity-&gt;get('field_accesstags')-&gt;referencedEntities());
  if (in_array('subscription', $accesstags)) {
    ... allow access ...
  }
  ...
}


I'm still wondering, if there is a simpler way (without having to iterate over the array of terms), but for now the solution works well. Thanks again for your help, @4k4.