diff -u b/core/includes/entity.inc b/core/includes/entity.inc --- b/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -53,6 +53,42 @@ * * @param string $entity_type * The entity type to load, e.g. node or user. + * @param mixed $id + * The id of the entity to load. + * @param bool $reset + * Whether to reset the internal cache for the requested entity type. + * + * @return \Drupal\Core\Entity\EntityInterface|null + * The entity object, or NULL if there is no entity with the given ID. + * + * @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0. Use + * The method overriding Entity::load() for the entity type, e.g. + * \Drupal\node\Entity\Node::load() if the entity type is known. If the + * entity type is variable, use the entity manager service to load the entity + * from the entity storage: + * @code + * \Drupal::entityManager()->getStorage($entity_type)->load($id) + * @endcode + * + * @see \Drupal\Core\Entity\EntityInterface::load() + * @see \Drupal\Core\Entity\EntityManagerInterface::getStorage() + * @see \Drupal\Core\Entity\EntityStorageInterface::load() + * @see \Drupal\Core\Entity\Sql\SqlContentEntityStorage + * @see \Drupal\Core\Entity\Query\QueryInterface + */ +function entity_load($entity_type, $id, $reset = FALSE) { + $controller = \Drupal::entityTypeManager()->getStorage($entity_type); + if ($reset) { + $controller->resetCache(array($id)); + } + return $controller->load($id); +} + +/** + * Loads an entity from the database. + * + * @param string $entity_type + * The entity type to load, e.g. node or user. * @param int $revision_id * The id of the entity to load. * @@ -102,6 +138,57 @@ } /** + * Loads multiple entities from the database. + * + * This function should be used whenever you need to load more than one entity + * from the database. The entities are loaded into memory and will not require + * database access if loaded again during the same page request. + * + * The actual loading is done through a class that has to implement the + * \Drupal\Core\Entity\EntityStorageInterface interface. By default, + * \Drupal\Core\Entity\Sql\SqlContentEntityStorage is used for content entities + * and Drupal\Core\Config\Entity\ConfigEntityStorage for config entities. Entity + * types can specify that a different class should be used by setting the + * "handlers['storage']" key in the entity plugin annotation. These classes + * can either implement the \Drupal\Core\Entity\EntityStorageInterface + * interface, or, most commonly, extend the + * \Drupal\Core\Entity\Sql\SqlContentEntityStorage class. See + * \Drupal\node\Entity\Node and \Drupal\node\NodeStorage for an example. + * + * @param string $entity_type + * The entity type to load, e.g. node or user. + * @param array $ids + * (optional) An array of entity IDs. If omitted, all entities are loaded. + * @param bool $reset + * Whether to reset the internal cache for the requested entity type. + * + * @return array + * An array of entity objects indexed by their IDs. + * + * @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0. Use + * The method overriding Entity::loadMultiple() for the entity type, e.g. + * \Drupal\node\Entity\Node::loadMultiple() if the entity type is known. If + * the entity type is variable, use the entity manager service to load the + * entity from the entity storage: + * @code + * \Drupal::entityManager()->getStorage($entity_type)->loadMultiple($id) + * @endcode + * + * @see \Drupal\Core\Entity\EntityInterface::loadMultiple() + * @see \Drupal\Core\Entity\EntityManagerInterface::getStorage() + * @see \Drupal\Core\Entity\EntityStorageInterface::loadMultiple() + * @see \Drupal\Core\Entity\Sql\SqlContentEntityStorage + * @see \Drupal\Core\Entity\Query\QueryInterface + */ +function entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE) { + $controller = \Drupal::entityTypeManager()->getStorage($entity_type); + if ($reset) { + $controller->resetCache($ids); + } + return $controller->loadMultiple($ids); +} + +/** * Load entities by their property values. * * @param string $entity_type diff -u b/core/modules/views/tests/src/Kernel/ViewStorageTest.php b/core/modules/views/tests/src/Kernel/ViewStorageTest.php --- b/core/modules/views/tests/src/Kernel/ViewStorageTest.php +++ b/core/modules/views/tests/src/Kernel/ViewStorageTest.php @@ -152,7 +152,7 @@ */ protected function displayTests() { // Check whether a display can be added and saved to a View. - $view = View::load'test_view_storage_new'); + $view = View::load('test_view_storage_new'); $new_id = $view->addDisplay('page', 'Test', 'test'); $display = $view->get('display');