Add implicit support for Trash

Created on 9 September 2025, about 7 hours ago

Problem/Motivation

Redirect currently does not play nicely with the trash module. Once redirects become revisionable Convert Redirect entity to revisionable Needs work , this will be problematic.

Steps to reproduce

  1. Apply the patch below.
  2. ddev drush si -y standard
  3. ddev drush en -y redirect
  4. Go to /admin/config/search/redirect/add and add a redirect /foo -> /bar
  5. Visit /foo
  6. Notice the error.

Error:

TypeError: Drupal\redirect\RedirectRepository::findByRedirect(): Argument #1 ($redirect) must be of type Drupal\redirect\Entity\Redirect, null given, called in /var/www/html/docroot/modules/contrib/redirect/src/RedirectRepository.php on line 125 in Drupal\redirect\RedirectRepository->findByRedirect() (line 149 of modules/contrib/redirect/src/RedirectRepository.php).

Drupal\redirect\RedirectRepository->findMatchingRedirect() (Line: 151)
Drupal\redirect\EventSubscriber\RedirectRequestSubscriber->onKernelRequestCheckRedirect() (Line: 246)
diff --git i/redirect.module w/redirect.module
index 4cfb3ca..1680c1b 100644
--- i/redirect.module
+++ w/redirect.module
@@ -15,6 +15,13 @@ use Drupal\redirect\Entity\Redirect;
 use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
 use Symfony\Component\Routing\Exception\RouteNotFoundException;
 
+function redirect_entity_storage_load(array &$entities, string $entity_type_id): void {
+  if ($entity_type_id === 'redirect') {
+    // Mimic what module trash would do for a deleted entity.
+    $entities = [];
+  }
+}
+
 /**
  * Implements hook_hook_info().
  */

Proposed resolution

Add a check to findMatchingRedirect to see if the ::load method actually returned an entity.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇸🇮Slovenia alecsmrekar

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024