简体   繁体   English

当已经有了它的机器名称时,如何获得节点内容类型的 label?

[英]how can I get the label of a node´s content type, when already having the machine name of it?

As an example: I have the machine name of the node bundle present.例如:我有节点包的机器名称。 eg "basic_page" and want to get the label of that bundle, in that example "Basic Page".例如“basic_page”并希望获得该捆绑包的 label,在该示例中为“基本页面”。

I can get that by loading a node of that bundle and then, geting its bundle and label like so:我可以通过加载该捆绑包的一个节点,然后像这样获取它的捆绑包和 label 来获得它:

node_load($nid)->type->entity->label();

but im searching for a more elegant, straight forward way without the need of loading the node.但我正在寻找一种更优雅、更直接的方式,而不需要加载节点。

If you already know the machine name, you should be able to use the EntityTypeManager如果您已经知道机器名称,您应该可以使用EntityTypeManager

\Drupal::entityTypeManager()->getDefinition('machine_name')->getLabel();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取当前计算机的AWS凭据? - How can I get the current machine's AWS credentials? 解析REST API:拥有通道名称,我可以在实际发送到Push之前获取设备类型吗? - Parse REST API: Having the channel name, can I get the device type before actually sending to Push? Drupal 7:如何从组件的prepocess函数中检索节点的Content Type? - Drupal 7: How do I retrieve a node's Content Type from within a component's prepocess function? $ _GET-如何从路径中获取名称和类型? - $_GET- how can i get name and type from the path? PHP太大时如何获取文件名? - PHP How can I get the file's name when it is too large? 如果已有内容,我如何获取xml标记的内部文本? - How do I get the inner text of a xml tag when there is already content in it? WordPress get_post_type,如何显示 label 的名称 - WordPress get_post_type, how to display name of label 如何在 php 中获取客户端机器的主机名或计算机名 - How to get client machine's hostname or computer name in php 如何解决:已经定义的“路由名称未定义” - How to solve: “route name not defined” when it's already defined 当您将数据悬停在Chart.js中时,如何更改标签名称? - How can I change the label name when you hover your data in Chart.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM