Problem/Motivation
In redirect_entity_delete()
the Symfony\Component\Routing\Exception\RouteNotFoundException
is caught with the following comment:
// This can happen if a module incorrectly defines a link template, ignore
// such errors.
However, calling the Url::getInternalPath()
in the try block can also produce a
Symfony\Component\Routing\Exception\MissingMandatoryParametersException
Steps to reproduce
I have such a case with the group_permissions module where the canonical route of the group_permission entity expects the group entity and not the group_permission entity.
1. Enable group_permissions and redirect modules
2. Create a group type 'Test' on /admin/group/types/add
3. Add a group on /group/add/test
4. Select an arbitrary permission on /group/1/permissions and save the page (this step is to create the group_permission entity)
5. Try to delete the group on /group/1/delete
Result:
Drupal\Core\Entity\EntityStorageException: Some mandatory parameters are missing ("group") to generate a URL for route "entity.group_permission.canonical". in Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete() (line 759 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Drupal\Core\Routing\UrlGenerator->getInternalPathFromRoute('entity.group_permission.canonical', Object, Array) (Line: 132)
Drupal\Core\Routing\UrlGenerator->getPathFromRoute('entity.group_permission.canonical', Array) (Line: 68)
Drupal\Core\Render\MetadataBubblingUrlGenerator->getPathFromRoute('entity.group_permission.canonical', Array) (Line: 802)
Drupal\Core\Url->getInternalPath() (Line: 78)
redirect_entity_delete(Object)
call_user_func_array(Object, Array) (Line: 426)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'redirect') (Line: 405)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_delete', Object) (Line: 433)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_delete', Array) (Line: 251)
Drupal\Core\Entity\EntityStorageBase->invokeHook('delete', Object) (Line: 903)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('delete', Object) (Line: 496)
Drupal\Core\Entity\EntityStorageBase->delete(Array) (Line: 751)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete(Array) (Line: 350)
Drupal\Core\Entity\EntityBase->delete() (Line: 16)
group_permissions_group_delete(Object)
call_user_func_array(Object, Array) (Line: 426)
...
Proposed resolution
Also catch the MissingMandatoryParametersException in the redirect delete hook.
Remaining tasks
User interface changes
API changes
Data model changes