Apologies if this has already been captured somewhere else. I did a search on the issue queue but couldn't see anything.
Feel free to close as a duplicate if already similar issue exists.
Problem/Motivation
After creating a menu link under any menu using module.links.menu.yml, it is not deleted even after deleting the module.
I created a simple test module to provide a single link. The only file I have in my module is test.links.menu.yml apart from test.info.yml file.
# External link.
test.drupal.org:
title: Drupal.org
description: Drupal is an open source platform for building amazing digital experiences.
url: https://www.drupal.org
menu_name: main
weight: 40
options:
attributes:
target: _blank
After installing the module, a new menu link appeared in main menu as expected.
Then I have changed the position of the menu / updated its weight and saved the changes.

Then uninstalled the module, still the link persists there. I tried clearing caches but no luck.
I found that `menu_tree` table still contains the data for my custom menu.

Note: I tried clearing the cache before uninstalling the module, this case works fine.
Steps to reproduce
- Create a module with custom menu link
- Enable the module and check the link is created.
- Change the weight of the link.
- Save the changes.
- Uninstall the module.
- Check the link persists.
- Try clearing cache.
- Check again, the link persists.
- Check database table menu_tree, the data for link still exists.
Expected Result
The menu link should be deleted.
Actual Result
The menu link persists.
Note: If I rebuild cache before uninstall (step 5), it works fine, the link also will be deleted.
Remaining tasks
Find the bug and resolve
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 3324291-nr-bot.txt | 1.56 KB | needs-review-queue-bot |
| Screenshot 2022-11-29 134114.png | 66.76 KB | sahal_va | |
| Screenshot 2022-11-29 133642.png | 45.67 KB | sahal_va |
Issue fork drupal-3324291
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
Comment #2
larowlanThe act of editing the link moves it into a menu override, if you check your config you should find it in the menu overrides config Object
If you want to remove it, you should be able to either delete the link or reimport your config from beforehand
Comment #3
sahal_va commentedHi @larowlan,
Thanks for this info.
But I am confused why it gets deleted when I rebuild cache before module uninstall.
It shows different behaviour in following 2 cases
Case 1:
In above case the link will not be deleted.
Case 2:
drush crIn above case the link will be deleted.
Can you explain why output for above two cases are different?
Comment #4
andypostI think it still a bug as users can just move a module provided link (to other menu for example) and later just delete the module but menu overrides/links should not throw fatal when link/override has non-existing router
PS: I came from #3324252: User account menu not editable after uninstall
Comment #5
larowlan> Can you explain why output for above two cases are different?
Uninstalling a module should clear the cache
Comment #6
sahal_va commented@larowlan
Sorry I didn't understand your reply.
Obviously uninstalling a module will clear cache.
Comment #7
larowlanOh sorry, I misread, you cleared the cache before you deleted
Comment #8
larowlanI'm not sure this is major
Comment #12
enaznin commentedComment #13
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #15
ameymudras commentedComment #16
smustgrave commentedThis will need a test case showing the issue.
Comment #17
slogar32 commentedi've posted an answer on Drupal Answers for a workaround, until this issue is fixed -> https://drupal.stackexchange.com/a/318397/104069