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
Issue links:
Description:
In Drupal 7 *_load() functions (node_load(), comment_load(), etc.) derived from entity_load() and also the menu loaders (*_load()) had returned FALSE in case of non-existent items. Now all *_load() functions should return NULL when the entity (or requested object) is not found.
Also, the load() method of your entity storage controllers (introduced in http://drupal.org/node/2032175) should return NULL when failing to retrieve the entity.
Entity loading wrapper
D7
function my_entity_load($id) {
$entities = entity_load('my_entity', array($id));
return $entities ? $entities[$id] : FALSE;
}
function my_entity_load_multiple($ids) {
return entity_load('my_entity', $ids);
}
D8
Use YourEntity::load() and YourEntity::loadMultiple()
Controller loading method
D8
class MyEntityStorage extends EntityStorageBase {
...
public function load($id) {
// Do whatever you need to get your entity.
...
return !empty($entity) ? $entity : NULL;
}
...
}
Note: Only necessary when not relying on the default load() method.
Impacts:
Module developers