diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 9a2748c..a3bb205 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -253,23 +253,19 @@ public function loadRevision($revision_id) { * {@inheritdoc} */ public function loadMultipleRevisions(array $revision_ids) { - $revisions = $this->doLoadRevisionFieldItems($revision_ids); + $revisions = $this->doLoadMultipleRevisionsFieldItems($revision_ids); // The hooks are executed with an array of entities keyed by the entity ID. // As we could load multiple revisions for the same entity ID at once we // have to build groups of entities where the same entity ID is present only // once. $entity_groups = []; + $entity_group_mapping = []; foreach ($revisions as $revision) { $entity_id = $revision->id(); - foreach ($entity_groups as &$entity_group) { - if (!isset($entity_group[$entity_id])) { - $entity_group[$entity_id] = $revision; - continue 2; - } - } - // If no suitable group has been found then create a new one. - $entity_groups[] = [$entity_id => $revision]; + $entity_group_key = isset($entity_group_mapping[$entity_id]) ? $entity_group_mapping[$entity_id] + 1 : 0; + $entity_group_mapping[$entity_id] = $entity_group_key; + $entity_groups[$entity_group_key][$entity_id] = $revision; } // Invoke the entity hooks for each group. @@ -284,13 +280,37 @@ public function loadMultipleRevisions(array $revision_ids) { /** * Actually loads revision field item values from the storage. * + * @param int|string $revision_id + * The revision identifier. + * + * @return \Drupal\Core\Entity\EntityInterface|null + * The specified entity revision or NULL if not found. + * + * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. + * \Drupal\Core\Entity\ContentEntityStorageBase::doLoadMultipleRevisionsFieldItems() + * should be implemented instead. + * + * @see https://www.drupal.org/node/2924915 + */ + abstract protected function doLoadRevisionFieldItems($revision_id); + + /** + * Actually loads revision field item values from the storage. + * * @param array $revision_ids * An array of revision identifiers. * * @return \Drupal\Core\Entity\EntityInterface[] * The specified entity revisions or an empty array if none are found. */ - abstract protected function doLoadRevisionFieldItems($revision_ids); + protected function doLoadMultipleRevisionsFieldItems($revision_ids) { + $revisions = []; + foreach ($revision_ids as $revision_id) { + $revisions[] = $this->doLoadRevisionFieldItems($revision_id); + } + + return $revisions; + } /** * {@inheritdoc} diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index 5da9b67..29b8a9a 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -613,15 +613,18 @@ protected function loadFromSharedTables(array &$values, array &$translations, $l /** * {@inheritdoc} */ - protected function doLoadRevisionFieldItems($revision_ids) { - // Support the case when a single revision ID is passed in. - $load_single = FALSE; - if (!is_array($revision_ids)) { - @trigger_error('Passing a single revision ID to "\Drupal\Core\Entity\ContentEntityStorageBase::doLoadRevisionFieldItems()" is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. An array of revision IDs should be given instead. See https://www.drupal.org/node/2924915.', E_USER_DEPRECATED); - $revision_ids = (array) $revision_ids; - $load_single = TRUE; - } + protected function doLoadRevisionFieldItems($revision_id) { + @trigger_error('"\Drupal\Core\Entity\ContentEntityStorageBase::doLoadRevisionFieldItems()" is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. "\Drupal\Core\Entity\ContentEntityStorageBase::doLoadMultipleRevisionsFieldItems()" should be implemented instead. See https://www.drupal.org/node/2924915.', E_USER_DEPRECATED); + + $revisions = $this->doLoadMultipleRevisionsFieldItems([$revision_id]); + + return !empty($revisions) ? reset($revisions) : NULL; + } + /** + * {@inheritdoc} + */ + protected function doLoadMultipleRevisionsFieldItems($revision_ids) { $revisions = []; // Sanitize IDs. Before feeding ID array into buildQuery, check whether @@ -639,7 +642,7 @@ protected function doLoadRevisionFieldItems($revision_ids) { } } - return $load_single ? (!empty($revisions) ? reset($revisions) : NULL) : $revisions; + return $revisions; } /** diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListener.php b/core/tests/Drupal/Tests/Listeners/DeprecationListener.php index 3630509..80b3d31 100644 --- a/core/tests/Drupal/Tests/Listeners/DeprecationListener.php +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListener.php @@ -111,7 +111,7 @@ public static function getSkippedDeprecations() { 'The Drupal\migrate_drupal\Plugin\migrate\source\d6\i18nVariable is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation', 'Implicit cacheability metadata bubbling (onto the global render context) in normalizers is deprecated since Drupal 8.5.0 and will be removed in Drupal 9.0.0. Use the "cacheability" serialization context instead, for explicit cacheability metadata bubbling. See https://www.drupal.org/node/2918937', 'Automatically creating the first item for computed fields is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\TypedData\ComputedItemListTrait instead.', - 'Passing a single revision ID to "\Drupal\Core\Entity\ContentEntityStorageBase::doLoadRevisionFieldItems()" is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. An array of revision IDs should be given instead. See https://www.drupal.org/node/2924915.', + '"\Drupal\Core\Entity\ContentEntityStorageBase::doLoadRevisionFieldItems()" is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. "\Drupal\Core\Entity\ContentEntityStorageBase::doLoadMultipleRevisionsFieldItems()" should be implemented instead. See https://www.drupal.org/node/2924915.', 'Passing a single revision ID to "\Drupal\Core\Entity\Sql\SqlContentEntityStorage::buildQuery()" is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. An array of revision IDs should be given instead. See https://www.drupal.org/node/2924915.', ]; }