Get Entity data and metadata | Drupal 8

Get Entity data and metadata

Submitted by editor on Tue, 01/10/2017 - 13:11
Question

How to get Entity type data and metadata

Get entity types list :

$itmes_list= \Drupal::entityTypeManager()->getDefinitions();

Get Entity type (Content / Config)

$itmes_list['node']->getGroup();
$itmes_list['node_type']->getGroup();

Get Label / Name

$itmes_list['node']->getLabel();

 

Load entity (dynamic type) from database

\Drupal::entityTypeManager()->getStorage($entity_type)->load($id);
See : https://api.drupal.org/api/drupal/core%21includes%21entity.inc/function/entity_load/8.3.x

Load a entity type using entityTypeManager

Example :
$nodeEntity = \Drupal::entityTypeManager()->getDefinition('node');

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.