From 2e45e93b5fffd0c40664b7b2c1b83313e761f5cf Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Fri, 26 Jul 2019 15:14:18 +0100 Subject: [PATCH] Issue #3069043 by mikelutz: Trigger an error on direct access of ContentEntityStorageBase::doLoadMultipleRevisionFieldItems() and mark it to be set abstract in Drupal 9 --- .../Core/Entity/ContentEntityStorageBase.php | 8 +++ .../LegacyContentEntityStorageBaseTest.php | 51 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 core/tests/Drupal/Tests/Core/Entity/LegacyContentEntityStorageBaseTest.php diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 3ec93063adff..95a1bab29477 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -608,13 +608,21 @@ abstract protected function doLoadRevisionFieldItems($revision_id); /** * Actually loads revision field item values from the storage. * + * This method should always be overridden and not called either directly or + * from parent::doLoadMultipleRevisionsFieldItems. It will be marked abstract + * in drupal:9.0.0 + * * @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. + * + * @todo Remove this logic and make the method abstract in + * https://www.drupal.org/project/drupal/issues/3069696 */ protected function doLoadMultipleRevisionsFieldItems($revision_ids) { + @trigger_error('Calling ' . __NAMESPACE__ . 'ContentEntityStorageBase::doLoadMultipleRevisionsFieldItems() directly is deprecated in drupal:8.8.0 and the method will be made abstract in drupal:9.0.0. Storage implementations should override and implement their own loading logic. See https://www.drupal.org/node/3069692', E_USER_DEPRECATED); $revisions = []; foreach ($revision_ids as $revision_id) { $revisions[] = $this->doLoadRevisionFieldItems($revision_id); diff --git a/core/tests/Drupal/Tests/Core/Entity/LegacyContentEntityStorageBaseTest.php b/core/tests/Drupal/Tests/Core/Entity/LegacyContentEntityStorageBaseTest.php new file mode 100644 index 000000000000..9ad6e831f117 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Entity/LegacyContentEntityStorageBaseTest.php @@ -0,0 +1,51 @@ +<?php + +namespace Drupal\Tests\Core\Entity; + +use Drupal\Core\Entity\ContentEntityNullStorage; +use PHPUnit\Framework\TestCase; + +/** + * Tests deprecated methods of ContentEntityStorageBase. + * + * @group Entity + * @group legacy + * + * @coversDefaultClass \Drupal\Core\Entity\ContentEntityStorageBase + */ +class LegacyContentEntityStorageBaseTest extends TestCase { + + /** + * Tests doLoadMultipleRevisionsFieldItems triggers an error. + * + * @covers ::doLoadMultipleRevisionsFieldItems + * + * @expectedDeprecation Calling Drupal\Core\EntityContentEntityStorageBase::doLoadMultipleRevisionsFieldItems() directly is deprecated in drupal:8.8.0 and the method will be made abstract in drupal:9.0.0. Storage implementations should override and implement their own loading logic. See https://www.drupal.org/node/3069692 + */ + public function testDoLoadMultipleRevisionFieldItems() { + $storage = new TestContentEntityStorageBase(); + $items = $storage->doLoadMultipleRevisionsFieldItems([]); + $this->assertSame([], $items); + } + +} + +/** + * Test class for ContentEntityStorageBaseTest. + */ +class TestContentEntityStorageBase extends ContentEntityNullStorage { + + /** + * Constructs a TestContentEntityStorageBase object. + */ + public function __construct() { + } + + /** + * {@inheritdoc} + */ + public function doLoadMultipleRevisionsFieldItems($revision_ids) { + return parent::doLoadMultipleRevisionsFieldItems($revision_ids); + } + +} -- GitLab