By claudiu.cristea on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Introduced in version:
8.0-ALPHA3
Description:
Early in 8.x branch but also in 7.x, the entity storage controllers method ->load() has returned a list of entities. This change renames the ->load() method into ->loadMultiple() and introduces the new ->load() method for single entity loading.
The new ->load() method takes a single entity ID as argument while ->loadMultiple() is still accepting an array with the list of IDs or NULL in order to return all entities.
Loading multiple entities
D7 (and early D8)
$ids = array(1, 200, ..., 345);
$controller = entity_get_controller('node');
$nodes = $controller->load($ids);
D8
$ids = array(1, 200, ..., 345);
$controller = \Drupal::entityManager()->getStorage('node');
$nodes = $controller->loadMultiple($ids);
Loading a single entity
D7 (and early D8)
$ids = array(345);
$controller = entity_get_controller('node');
$entities = $controller->load($ids);
$node = reset($entities);
D8
$id = 345;
$controller = \Drupal::entityManager()->getStorage('node');
$node = $controller->load($id);
Impacts:
Module developers