Problem/Motivation

Redirect currently does not play nicely with the trash module. Once redirects become revisionable, 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

Issue fork redirect-3545692

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

alecsmrekar created an issue. See original summary.

alecsmrekar’s picture

Assigned: alecsmrekar » Unassigned
Status: Active » Needs review
amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me :) Since this is just a load safety check, I don't think it needs test coverage.

amateescu’s picture

Opened a sibling issue in the Trash queue: #3547405: Integration with the Redirect module

  • berdir committed 9bf7bd38 on 8.x-1.x authored by alecsmrekar
    feat: #3545692 Add implicit support for Trash
    
    By: alecsmrekar
    By:...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Merged.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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