verfranzt
verfranzt

Reputation: 56

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. e.g "basic_page" and want to get the label of that bundle, in that example "Basic Page".

I can get that by loading a node of that bundle and then, geting its bundle and label like so:

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

but im searching for a more elegant, straight forward way without the need of loading the node.

Upvotes: 0

Views: 1001

Answers (1)

msg
msg

Reputation: 8181

If you already know the machine name, you should be able to use the EntityTypeManager

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

Upvotes: 1

Related Questions