drupal 8 get taxonomy term value in node

后端 未结 6 957
既然无缘
既然无缘 2021-02-08 05:36

Drupal\\node\\Entity\\Node Object ( [in_preview] => [values:protected] => Array ( [vid] => Array ( [x-default] =

6条回答
  •  爱一瞬间的悲伤
    2021-02-08 06:04

    entity property can be accessed directly from any reference type field.

    $node = 'myNode';
    $termEntity = $node->get('field_taxonomy_reference')->entity;
    if ($termEntity instanceof TermInterface) {
      $termLabel = $termEntity->label();
    }
    

提交回复
热议问题