March 2019
Intermediate to advanced
580 pages
15h 3m
English
Now that we have our entity IDs found by the query, it's time to load them. It couldn't be simpler to do so. We just use the storage handler for that entity type (and we get that from the entity type manager):
$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($ids);
This will return an array of EntityInterface objects (in this case NodeInterface). Or if we have only one ID to load:
$nodes = \Drupal::entityTypeManager()->getStorage('node')->load($id);
These will return a single NodeInterface object.
The Entity type storage handler also has a shortcut method that allows you to perform simple queries and load the resulting entities in one go. For example, if we wanted to load all article nodes:
$nodes ...
Read now
Unlock full access