diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 875ff23..b1da527 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -183,6 +183,32 @@ public function finalizePurge(FieldStorageDefinitionInterface $storage_definitio /** * {@inheritdoc} */ + public function loadRevision($revision_id) { + $revision = $this->doLoadRevisionFieldItems($revision_id); + + if ($revision) { + $entities = [$revision]; + $this->invokeStorageLoadHook($entities); + $this->postLoad($entities); + } + + return $revision; + } + + /** + * Actually loads revision field item values from the storage. + * + * @param int $revision_id + * The revision identifier. + * + * @return \Drupal\Core\Entity\ContentEntityInterface|null + * The re + */ + abstract protected function doLoadRevisionFieldItems($revision_id); + + /** + * {@inheritdoc} + */ protected function doSave($id, EntityInterface $entity) { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ @@ -218,14 +244,24 @@ protected function doSave($id, EntityInterface $entity) { * @param string[] $names * (optional) The name of the fields to be written to the storage. If an * empty value is passed all field values are saved. - * - * @api */ abstract protected function doSaveFieldItems(ContentEntityInterface $entity, array $names = []); /** * {@inheritdoc} */ + protected function doPreSave(EntityInterface $entity) { + /** @var \Drupal\Core\Entity\ContentEntityBase $entity */ + + // Sync the changes made in the fields array to the internal values array. + $entity->updateOriginalValues(); + + return parent::doPreSave($entity); + } + + /** + * {@inheritdoc} + */ protected function doPostSave(EntityInterface $entity, $update) { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ @@ -257,8 +293,6 @@ protected function doDelete($entities) { * * @param \Drupal\Core\Entity\ContentEntityInterface[] $entities * An array of entity objects to be deleted. - * - * @api */ abstract protected function doDeleteFieldItems($entities); @@ -283,8 +317,6 @@ public function deleteRevision($revision_id) { * * @param \Drupal\Core\Entity\ContentEntityInterface $revision * An entity revision object to be deleted. - * - * @api */ abstract protected function doDeleteFieldItemsRevision(ContentEntityInterface $revision); @@ -332,27 +364,6 @@ protected function invokeStorageLoadHook(array &$entities) { } /** - * Invokes hook_entity_load_uncached(). - * - * @param \Drupal\Core\Entity\ContentEntityInterface[] $entities - * List of entities, keyed on the entity ID. - */ - protected function invokeLoadUncachedHook(array &$entities) { - if (!empty($entities)) { - // Call hook_entity_load_uncached(). - foreach ($this->moduleHandler()->getImplementations('entity_load_uncached') as $module) { - $function = $module . '_entity_load_uncached'; - $function($entities, $this->entityTypeId); - } - // Call hook_TYPE_load_uncached(). - foreach ($this->moduleHandler()->getImplementations($this->entityTypeId . '_load_uncached') as $module) { - $function = $module . '_' . $this->entityTypeId . '_load_uncached'; - $function($entities); - } - } - } - - /** * {@inheritdoc} */ protected function invokeHook($hook, EntityInterface $entity) { diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php index 61b6511..514f82a 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -456,7 +456,7 @@ protected function doPreSave(EntityInterface $entity) { * * @param \Drupal\Core\Entity\EntityInterface $entity * The saved entity. - * @param $update + * @param bool $update * Specifies whether the entity is being updated or created. */ protected function doPostSave(EntityInterface $entity, $update) { diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index 28d668c..c98aa19 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -398,10 +398,9 @@ protected function doLoadMultiple(array $ids = NULL) { // Load any remaining entities from the database. if ($entities_from_storage = $this->getFromStorage($ids)) { $this->invokeStorageLoadHook($entities_from_storage); + $this->setPersistentCache($entities_from_storage); } - $this->setPersistentCache($entities_from_storage); - return $entities_from_cache + $entities_from_storage; } @@ -567,7 +566,9 @@ protected function loadFromSharedTables(array &$values, array &$translations) { /** * {@inheritdoc} */ - public function loadRevision($revision_id) { + protected function doLoadRevisionFieldItems($revision_id) { + $revision = NULL; + // Build and execute the query. $query_result = $this->buildQuery(array(), $revision_id)->execute(); $records = $query_result->fetchAllAssoc($this->idKey); @@ -575,12 +576,13 @@ public function loadRevision($revision_id) { if (!empty($records)) { // Convert the raw records to entity objects. $entities = $this->mapFromStorageRecords($records, TRUE); - $this->postLoad($entities); $entity = reset($entities); if ($entity) { - return $entity; + $revision = $entity; } } + + return $revision; } /** @@ -745,9 +747,6 @@ protected function doDeleteFieldItems($entities) { public function save(EntityInterface $entity) { $transaction = $this->database->startTransaction(); try { - // Sync the changes made in the fields array to the internal values array. - $entity->updateOriginalValues(); - $return = parent::save($entity); // Ignore replica server temporarily. diff --git a/core/modules/user/src/UserStorage.php b/core/modules/user/src/UserStorage.php index 590950d..91d7a6f 100644 --- a/core/modules/user/src/UserStorage.php +++ b/core/modules/user/src/UserStorage.php @@ -9,6 +9,7 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -72,14 +73,14 @@ public static function createInstance(ContainerInterface $container, EntityTypeI /** * {@inheritdoc} */ - public function save(EntityInterface $entity) { + protected function doSaveFieldItems(ContentEntityInterface $entity, array $names = []) { // The anonymous user account is saved with the fixed user ID of 0. // Therefore we need to check for NULL explicitly. if ($entity->id() === NULL) { $entity->uid->value = $this->database->nextId($this->database->query('SELECT MAX(uid) FROM {users}')->fetchField()); $entity->enforceIsNew(); } - return parent::save($entity); + return parent::doSaveFieldItems($entity, $names); } /**