Menu link created by modules are not deleted on module uninstall

Created on 29 November 2022, over 1 year ago
Updated 15 February 2024, 4 months ago

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

  1. Create a module with custom menu link
  2. Enable the module and check the link is created.
  3. Change the weight of the link.
  4. Save the changes.
  5. Uninstall the module.
  6. Check the link persists.
  7. Try clearing cache.
  8. Check again, the link persists.
  9. 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

🐛 Bug report
Status

Needs work

Version

9.5

Component
Menu system 

Last updated 4 days ago

Created by

🇮🇳India sahal_va

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024