drupal 8在节点中获取分类学术语值 [英] drupal 8 get taxonomy term value in node

查看:176
本文介绍了drupal 8在节点中获取分类学术语值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Drupal\node\Entity\Node对象

[in_preview] =>
[values:protected] =>数组

[ vid] =>数组

[x-default] => 1

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

        [langcode] => Array
            (
                [x-default] => en
            )

        [field_destination] => Array
            (
                [x-default] => Array
                    (
                        [0] => Array
                            (
                                [target_id] => 2
                            )

                    )

            )

无法直接获取field_destination值。这是与内容类型关联的分类术语。需要任何帮助。

Not able to get field_destination value directly. It's a taxonomy term attached with the content type. Any help appriciated.

推荐答案

VJamie的答案。

To build on VJamie's answer.

您需要在脚本顶部设置use语句;

You will need to either set a use statement at the top of your script;

use Drupal\taxonomy\Entity\Term;

或者为类实例添加名称空间前缀;

Or, prefix the class instance with the namespace;

$term = \Drupal\taxonomy\Entity\Term::load($node->get('field_destination')->target_id);

这将消除致命伤。

这篇关于drupal 8在节点中获取分类学术语值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆