From e5de05353fab82ef9eb8f490374420f4fbbfe99a Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Wed, 6 Mar 2013 21:53:22 +0000 Subject: [PATCH] Issue #1919322 by plach: Entity_load_unchanged() should be part of the storage controller. --- core/includes/entity.inc | 7 +++---- .../Core/Config/Entity/ConfigStorageController.php | 9 +++++++++ .../Core/Entity/DatabaseStorageController.php | 9 +++++++++ .../Entity/EntityStorageControllerInterface.php | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 37fb3105e9eb..708706e0d7f6 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -297,10 +297,9 @@ function entity_load_multiple_by_properties($entity_type, array $values) { * The unchanged entity, or FALSE if the entity cannot be loaded. */ function entity_load_unchanged($entity_type, $id) { - $controller = drupal_container()->get('plugin.manager.entity')->getStorageController($entity_type); - $controller->resetCache(array($id)); - $result = $controller->load(array($id)); - return reset($result); + return drupal_container()->get('plugin.manager.entity') + ->getStorageController($entity_type) + ->loadUnchanged($id); } /** diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index a957e4d4ed76..92e4be39020d 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -142,6 +142,15 @@ public function load(array $ids = NULL) { return $entities; } + /** + * Implements \Drupal\Core\Entity\EntityStorageControllerInterface::loadUnchanged() + */ + public function loadUnchanged($id) { + $this->resetCache(array($id)); + $result = $this->load(array($id)); + return reset($result); + } + /** * Implements Drupal\Core\Entity\EntityStorageControllerInterface::loadRevision(). */ diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php index 9092a1372490..1c7d9fd13d44 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -235,6 +235,15 @@ public function load(array $ids = NULL) { return $entities; } + /** + * Implements \Drupal\Core\Entity\EntityStorageControllerInterface::loadUnchanged() + */ + public function loadUnchanged($id) { + $this->resetCache(array($id)); + $result = $this->load(array($id)); + return reset($result); + } + /** * Implements \Drupal\Core\Entity\EntityStorageControllerInterface::loadRevision(). */ diff --git a/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php index ef69cb6a1a45..4ac5d9a19984 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php @@ -40,6 +40,20 @@ public function resetCache(array $ids = NULL); */ public function load(array $ids = NULL); + /** + * Loads an unchanged entity from the database. + * + * @param mixed $id + * The ID of the entity to load. + * + * @return \Drupal\Core\Entity\EntityInterface + * The unchanged entity, or FALSE if the entity cannot be loaded. + * + * @todo Remove this method once we have a reliable way to retrieve the + * unchanged entity from the entity object. + */ + public function loadUnchanged($id); + /** * Load a specific entity revision. * -- GitLab