Problem/Motivation

entity_revision_load() and entity_revision_delete() are marked as @deprecated for removal before Drupal 9.0.0.

Proposed resolution

Replace usages of these deprecated methods with their service-based replacements:

\Drupal::entityTypeManager()->getStorage($entity_type)->loadRevision($revision_id);

\Drupal::entityTypeManager()->getStorage($entity_type)>deleteRevision($revision_id);

Remaining tasks

File an issue to remove these methods in Drupal 9.

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mile23 created an issue. See original summary.

Mile23’s picture

Issue summary: View changes
Mile23’s picture

Issue summary: View changes
Mile23’s picture

The patch.

This isn't a meta because it's not that many replacements.

Mile23’s picture

Mile23’s picture

Mile23’s picture

Mile23’s picture

Version: 8.2.x-dev » 8.3.x-dev

Patch still applies to 8.3.x.

Removes all entity_revision* usages.

Re-running test.

daffie’s picture

Status: Needs review » Needs work

In the test Drupal\field\Tests\FormTest on line 578 there is the following comment: "$entity = entity_revision_load($entity_type, $entity->getRevisionId());". Can we replace that usage also?

All other usages for entity_revision_load() and entity_revision_delete() have been removed from the code base. The patch looks great. Almost RTBC for me.

urvigala’s picture

Assigned: Unassigned » urvigala
sneha_surve’s picture

Assigned: urvigala » sneha_surve
sneha_surve’s picture

Assigned: sneha_surve » Unassigned
Status: Needs work » Needs review
FileSize
979 bytes

Applied patch as per said in #9.

Thanks!

timmillwood’s picture

Merging the patches in #7 and #12. Interdiff is based on #7.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.
All usages for entity_revision_load() and entity_revision_delete() have been removed from the code base.
The patch looks great.

I have one nitpick left, but that can be done on commit.

+++ b/core/modules/field/src/Tests/FormTest.php
@@ -575,7 +575,9 @@ function testFieldFormAccess() {
+    $entity = $this->container->get('entity_type.manager')
+        ->getStorage($entity_type)
+        ->loadRevision($entity->getRevisionId());

Sorry for nitpicking, but if you do this multiline then the second and third lines should be only 2 spaces indented and not 4 spaces. As an alternative you can put it on a single line.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
diff --git a/core/modules/field/src/Tests/FormTest.php b/core/modules/field/src/Tests/FormTest.php
index d7d9f2c..f868f7a 100644
--- a/core/modules/field/src/Tests/FormTest.php
+++ b/core/modules/field/src/Tests/FormTest.php
@@ -576,8 +576,8 @@ function testFieldFormAccess() {
 
     // Check that the revision is also saved in the revisions table.
     $entity = $this->container->get('entity_type.manager')
-        ->getStorage($entity_type)
-        ->loadRevision($entity->getRevisionId());
+      ->getStorage($entity_type)
+      ->loadRevision($entity->getRevisionId());
     $this->assertEqual($entity->$field_name_no_access->value, 99, 'New revision has the expected value for the field with no edit access.');
     $this->assertEqual($entity->$field_name->value, 2, 'New revision has the expected value for the field with edit access.');
   }

Fixed on commit.

Committed 4d8efc4 and pushed to 8.3.x. Thanks!

diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc
index f7bc397..dc1be65 100644
--- a/core/modules/node/node.admin.inc
+++ b/core/modules/node/node.admin.inc
@@ -6,7 +6,6 @@
  */
 
 use Drupal\node\NodeInterface;
-use Drupal\node\Entity\Node;
 
 /**
  * Updates all nodes in the passed-in array with the passed-in field values.

Removed unused use on commit.

  • alexpott committed 4d8efc4 on 8.3.x
    Issue #2741249 by Mile23, timmillwood, sneha_surve: Remove...
Eric_A’s picture

--- a/core/modules/field/src/Tests/FormTest.php
+++ b/core/modules/field/src/Tests/FormTest.php
@@ -575,7 +575,9 @@ function testFieldFormAccess() {
     $this->assertEqual($entity->$field_name->value, 2, 'New revision has the expected value for the field with edit access.');
 
     // Check that the revision is also saved in the revisions table.
-//    $entity = entity_revision_load($entity_type, $entity->getRevisionId());
+    $entity = $this->container->get('entity_type.manager')
+        ->getStorage($entity_type)
+        ->loadRevision($entity->getRevisionId());

This is uncommenting code apart from replacing the deprecated function (and fixing indentation). Nothing seems to have broken, but quite a big change for this issue.

Eric_A’s picture

Status: Fixed » Reviewed & tested by the community

Seriously, this either needs a revert or some feedback. Why did we bring back that dead code in #12 and #13? Was it on purpose or a by accident? We could have converted dead code without uncommenting, we could have deleted dead code, but bringing it back in a conversion issue without any comment whatsoever is.. weird.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: remove_entity_revision-2741249-13.patch, failed testing.

Eric_A’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

@Eric_A it is a test - let's worry about the important things. The commenting out erroneously occurred in #1822000: Remove Drupal\field_test\Plugin\Entity\Type\TestEntity in favor of EntityTest (probably as part of getting the patch to work but was missed on review). The test is pretty meaningless - but it is hardly alone in that.

Eric_A’s picture

Having this in 8.3.x but not in 8.2.x does make it harder to port some 8.3.x patches or forward port 8.2.x patches, like for example coding standard patches.

So we had erroneous changes to FormTest twice, but luckily the test is pretty meaningless. Sigh, ok. Thanks for the feedback.

alexpott’s picture

@Eric_A well in that case just target 8.3.x first and if there's energy to backport to 8.2.x so be it.

Eric_A’s picture

well in that case just target 8.3.x first and if there's energy to backport to 8.2.x so be it.

I do understand there's some hesitance to cherry-pick this task to 8.2.x now that it is in beta, but is the above really the policy for 8.2.x bug fixes? That would be a shame, cause then 8.2.x became half dead right after 8.3.x opened. Some policies are hard to track, I thought the policy here was to open bug fixes against the current minor (Not sure if that would be 8.1.x or 8.2.x right now) even if we commit to the latest open branch first.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.