Delete menus when relationship is deleted
When a group relationship pointing to a group_content_menu entity is deleted, the menu itself should also be removed if it has no remaining relationships. Previously, deleting a relationship left orphaned menus in the system with no way to access or manage them.
Additionally, during entity deletion flows, other modules (e.g. redirect) call toUrl() in entity_delete hooks. Since the group relationship may already be removed from the database at that point, urlRouteParameters() would throw an EntityMalformedException because it could no longer look up the owning group.
Changes:
-
Add groupRelationshipDelete() hook in GroupContentMenuHooks that listens for group_relationship_delete events. When the last relationship for a menu is removed, the menu is automatically deleted.
-
Add static $deletingMenus re-entry guard to entityPredelete() to prevent infinite recursion: deleting a menu triggers relationship deletion, which would otherwise trigger menu deletion again.
-
Add setRouteParameters() method and $cachedRouteParameters property to GroupContentMenu entity. This allows route parameters (group ID, bundle) to be cached before the relationship is removed, so that urlRouteParameters() can still produce valid URLs during delete hooks even when the relationship no longer exists in the database.
-
Cache route parameters in entityPredelete() (for the menu-initiated deletion path) and in groupRelationshipDelete() (for the relationship-initiated deletion path) before the actual deletion proceeds.
-
Add GroupContentMenuHooksTest with two kernel tests:
- Menu is deleted when its only relationship is removed
- Menu is NOT deleted when other relationships remain
-
Extend GroupContentMenuEntityTest with testToUrlWithCachedRouteParameters() to verify toUrl() works when route parameters are pre-cached.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
Closes #3578503