8.4.x Entity.php public static Entity::load($id)
8.0.x Entity.php public static Entity::load($id)
8.1.x Entity.php public static Entity::load($id)
8.2.x Entity.php public static Entity::load($id)
8.3.x Entity.php public static Entity::load($id)
8.5.x Entity.php Entity::load($id)

Loads an entity.


mixed $id: The id of the entity to load.

Return value

static The entity object or NULL if there is no entity with the given ID.

Overrides EntityInterface::load


core/lib/Drupal/Core/Entity/Entity.php, line 497


Defines a base entity class.




public static function load($id) {
  $entity_manager = \Drupal::entityManager();
  return $entity_manager->getStorage($entity_manager->getEntityTypeFromClass(get_called_class()))->load($id);


Insasse’s picture

entity_load is an awesome function it is a pitty that there is non equivalent function out there :(

ec0g’s picture

// $entity_type could be "node" "taxonomy_term" etc...


a.dmitriiev’s picture

@Insasse, please read this: https://docs.acquia.com/article/lesson-62-loading-entities

You can do :

// Get a node storage object.
$node_storage = \Drupal::entityManager()->getStorage('node');

// Load a single node.

// Load multiple nodes.

Andy_D’s picture

This method uses deprecated functions - I'm currently researching alternatives!

merauluka’s picture

The method still works. Just switch out entityManager() with entityTypeManager().


Neograph734’s picture

Every entity in Drupal extends the Entity class. If you need to load a node, you can use Drupal\node\Entity\Node::load($nid); or Drupal\node\Entity\Node::loadMultiple($nids); This will call the above functions via class inheritance.

Or cleaner:

// Define usage at the top of your file.
use Drupal\node\Entity\Node;

// Later on there is no need to provide the entire namespace.