How do I get machine name by entity type and its ID?
The code I am using is the following.
$block = \Drupal\block_content\Entity\BlockContent::load(2); $render = \Drupal::entityTypeManager()-> getViewBuilder('block_content')->view($block);
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
To get the type and id of a given entity, you can do:
$type = $entity->bundle(); $id = $entity->id();
Some entities, like Node, provide wrapper methods to return the bundle:
$type = $node->getType();
But Block doesn't. So if it is Block that you are after:
$block = \Drupal\block_content\Entity\BlockContent::load(2); $type = $block->bundle(); $id = $block->id();