Problem
When you delete a menu link (directly or through deleting a node with menu link and fireing the hook menu_link_content_entity_predelete), if the menu link had any children, their reference to the parent gets orphaned in the MenuLinkContent entity, but is remapped to the grandparent in the menu_tree table by the MenuTreeStorage.
Depending on the data displayed you will see the orphaned children menu links moved up 1 level, or pointing to the root menu. In the database the menu_link_content_data.parent column contains a reference to a non-existing entity. This can cause errors and problems.
Steps to reproduce
- clean install D8.6 dev
- create 3 nested menu links in a menu, e.g. in Main Navigation
- delete the 'middle' menu link
- look at /admin/structure/menu/manage/main: this should show link 3 as child of link 1
- edit link 3: this should show the parent link as the menu root, not link 1
Proposed resolution
Take the logic of remapping parent references to the grandparent as used in \Drupal\Core\Menu\MenuTreeStorage::delete and apply this to \Drupal\menu_link_content\Entity\MenuLinkContent::preDelete too.
Remaining tasks
- Create a patch
- Add automated tests
User interface changes
None.
API changes
None.
Data model changes
After deleting MenuLinkContent entities any children will have their parent refs remapped to their grantparent in both data tables: menu_tree and menu_link_content_data.
Comment | File | Size | Author |
---|---|---|---|
#11 | 2951548-11.patch | 2.98 KB | finne |
#11 | 2951548-11-test-only.patch | 1.98 KB | finne |
#9 | 2951548-9.patch | 2.75 KB | finne |
#9 | 2951548-9-test-only.patch | 1.76 KB | finne |
#6 | 2951548-6.patch | 2.88 KB | finne |
Comments
Comment #2
finneComment #3
finneComment #4
finneComment #5
finneComment #6
finneCreated patch for this issue, including test.
Comment #7
finneComment #8
idebr CreditAttribution: idebr at ezCompany commentedMenu link content children are re-reparented correct after the patch.
However, there are a few unused statement in your test.
Comment #9
finneRerolled patch and added test-only patch.
Comment #10
finneComment #11
finneimproved test to actually test if the correct parent ID is set.
Comment #14
idebr CreditAttribution: idebr at ezCompany commentedTest coverage looks good now, settings to RTBC.
Comment #15
alexpottI tested this on Drupal 7 add can confirm this is a regression.
Committed and pushed 2cdab9c011 to 8.6.x and 9e3a46258e to 8.5.x. Thanks!