By berdir on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
In Drupal 7, entity_load() returned an array of results, despite its name. For consistency with other load functions, the existing function has now been renamed to entity_load_multiple().
Additionally, a new entity_load() function has been added that does load and return a single entity.
Examples
Drupal 7
// Load multiple entities.
$entities = entity_load('entity_type', array(1, 2));
// Load a single entity.
$entities = entity_load('entity_type', array(1));
$entity = reset($entities);
Drupal 8
// Load multiple entities.
$entities = entity_load_multiple('entity_type', array(1, 2));
// Load a single entity.
$entity = entity_load('entity_type', 1);
A simple rename might not be enough: entity_load('entity_type', FALSE) loaded all entities. Use entity_load_multiple('entity_type') instead or entity_load_multiple('entity_type', NULL). Passing FALSE to entity_load_multiple leads to a fatal error.
If the entity type class is known, $EntityTypeClass::load() and loadMultiple() can be used.
Impacts:
Module developers