[英]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.