O'Reilly logo

Drupal 8 Module Development by Daniel Sipos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading entities

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 = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required