Problem/Motivation
Redirect currently does not play nicely with the trash module. Once redirects become revisionable, this will be problematic.
Steps to reproduce
- Apply the patch below.
- ddev drush si -y standard
- ddev drush en -y redirect
- Go to /admin/config/search/redirect/add and add a redirect /foo -> /bar
- Visit /foo
- 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
Comments
Comment #3
alecsmrekar commentedComment #4
amateescu commentedLooks good to me :) Since this is just a load safety check, I don't think it needs test coverage.
Comment #5
amateescu commentedOpened a sibling issue in the Trash queue: #3547405: Integration with the Redirect module
Comment #7
berdirMerged.