Problem/Motivation

Drupal 9 has removed the service 'path.alias_storage' and have been reverted to revisionable entities, see link to drupal 9 documentation.

Steps to reproduce

  1. Enable the current tombstone module, configure it to delete any content type
  2. Create a dummy content type of the type set above and then proceed to delete it
  3. Webpage will white screen and the error in the log will be something along the line of "You have requested a non-existent service "path.alias_storage". in Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete() "

Proposed resolution

Following the instructions here, the following code/patch is proposed to allow for tombstones to work with Drupal 9

diff --git a/src/TombstonesService.php b/src/TombstonesService.php
index 5afcae4..f080092 100644
--- a/src/TombstonesService.php
+++ b/src/TombstonesService.php
@@ -58,7 +58,14 @@ class TombstonesService {
       'field_tombstone_path' => $tombstone_metadata['path'],
     ]);
     $tombstone->save();
-    \Drupal::service('path.alias_storage')->save("/node/" . $tombstone->id(), $tombstone_metadata['path'], "en");
+    
+    $path_alias = \Drupal::entityTypeManager()->getStorage('path_alias')->create([
+      'path' => "/node/" . $tombstone->id(),
+      'alias' => $tombstone_metadata['path'],
+      'langcode' => "en",
+    ]);
+    $path_alias->save();
+    \Drupal::entityTypeManager()->getStorage('path_alias')->save($path_alias);
   }
 
 }

Thanks!

CommentFileSizeAuthor
drupal9-tombstone.patch752 bytestocao19

Issue fork tombstones-3228123

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tocao19 created an issue. See original summary.

avpaderno’s picture

Status: Active » Needs review
avpaderno’s picture

Status: Needs review » Needs work

Given that Drupal releases before 8.9.x aren't anymore supported, and the path.alias_storage service has been removed from Drupal 8.8.0, sites using this module are now facing this error.

+    $path_alias->save();
+    \Drupal::entityTypeManager()->getStorage('path_alias')->save($path_alias);

Only one of those lines is required to save the path alias entity, preferably the first one.

abramm made their first commit to this issue’s fork.

abramm’s picture

Status: Needs work » Needs review
abramm’s picture

Version: 8.x-1.0-alpha3 » 2.0.x-dev

  • abramm committed 461fdbb2 on 2.0.x
    Issue #3228123: You have requested a non-existent service "path....
abramm’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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