Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Updated: Comment #20
Problem/Motivation
A programatically added menu item is not removed from the menu after the menu link code has been removed.
Steps to reproduce
- Create a module with a single route and callback.
- Add a menu link to the route using an implementation of
hook_menu_link_defaults()
. Add the menu link to the 'main' menu (for convenience). - Enable the module.
- Check that the menu link appears in the main menu.
- Remove the code from MODULE_menu_link_defaults().
- Clear the cache
- Observe that the menu link is stil in the main menu.
Proposed resolution
Remaining tasks
- None (patch in #29 is ready for review)
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#29 | interdiff.txt | 211 bytes | joegraduate |
#29 | programatically_added-1079628-29-d7.patch | 3.58 KB | joegraduate |
#24 | programatically_added-1079628-24-d7.patch | 3.61 KB | joegraduate |
#14 | drupal_1079628_menu_type_change_13.patch | 3.75 KB | hefox |
#3 | menu_alter_callback-1079628-3.patch | 4.52 KB | Caligan |
Comments
Comment #1
Caligan CreditAttribution: Caligan commentedSuccessfully replicated this with the provided steps. Menu items registered in the menu_links table that are later turned into MENU_CALLBACKs (which should not be in menu_links) aren't removed from the table by _menu_navigation_links_rebuild() because their paths are still valid.
This patch sieves for MENU_CALLBACK items and removes them from menu_links along with any stale entries.
Comment #2
ins0mn1ac22 CreditAttribution: ins0mn1ac22 commentedpatch looks good. nitpick:
missing a space after 'router_path' in the second db_or() condition.
here are some hints to help you build a test:
Comment #3
Caligan CreditAttribution: Caligan commentedPatch bundled with a test verifying that menu items changed to MENU_CALLBACK are removed from menu_links table (and so from visible menus).
Comment #4
sunComment #5
sun#1148940: Menu links not removed from menu has been marked as duplicate
Comment #6
Blackice2999 CreditAttribution: Blackice2999 commentedHi,
works fine for me. It can be good tested with Views and also fixes: #1029022: Menu item created in a view is not removed from the menu when removed from the view
Comment #7
sunThis needs some more reviews, especially from menu system maintainers.
I don't have time myself right now, but will try to come back to this issue shortly.
Comment #8
yoroy CreditAttribution: yoroy commentedRelated major bug: #550254: Menu links are sometimes not properly re-parented
Comment #9
sunWhy isn't this simply an "else" ?
-2 days to next Drupal core point release.
Comment #10
hefox CreditAttribution: hefox commentedSame question as sun; switching to other type of menu items other than normal item, like local tasks, will make them not-menu-links, so it'd only work for a subset of links it needs to.
Why keep track of both path and item if only using path? Seems like a waist of memory to keep track of extra information.
Comment #11
drzraf CreditAttribution: drzraf commentedthe patch (#3) did not removed the menu entry created by a view (dup: #1418618: Views may leave stale menu entries)
Comment #12
hefox CreditAttribution: hefox commentedComment #13
hefox CreditAttribution: hefox commentedHere's a slightly different take on it
Patch:
Didn't really change the actual test other than the function call that sets the static.
Comment #14
hefox CreditAttribution: hefox commentedRight.. the patch.
Comment #15
cweagansUpdating tags per http://drupal.org/node/1517250
Comment #16
ifernando CreditAttribution: ifernando commentedThe patch menu_callback_drop-1079628-1.patch works for me.
Comment #17
jibran#14: drupal_1079628_menu_type_change_13.patch queued for re-testing.
Comment #19
Sutharsan CreditAttribution: Sutharsan commentedSince the original report and patches the menu system got a full overhaul, but the problem still remains. Changing issue title and description to match the current situation.
Comment #20
joegraduateAs far as I can tell, this is no longer a problem in Drupal 8.0.x. Just tested a clean install of Drupal 8.0.4 and this issue does not exist. This is still a problem in 7.x, however.
Comment #21
joegraduateThe attached patch is a backport of #14. This patch fixes the problem for me in the latest 7.x-dev version of Drupal core.
Comment #22
joegraduateComment #24
joegraduateUpdated patch with fixed tests.
Comment #25
joegraduateComment #26
joegraduatePatch in #24 still applies cleanly to the latest 7.x-dev and 7.44.
Comment #27
joegraduatePatch in #24 still applies cleanly to the latest 7.x-dev and 7.50. Please review!
Comment #28
Sutharsan CreditAttribution: Sutharsan commentedIf I interpret the code correctly the conditions are _and_-ed. The description says _or_. If I'm right one must be corrected. (but I have to be careful with negative logic)
Comment #29
joegraduateGood catch, @Sutharsan. I've updated the confusing comment you identified to more accurately describe what is happening.
Comment #30
joegraduateComment #31
joegraduateComment #32
kopeboy CreditAttribution: kopeboy commentedGuys, how to delete an orphaned menu item before this is commited!?
I have menu items on main menu that were created with Page Manager. The pages were deleted and now I can't change paths or delete them.
I even tried recreating pages with the same path, change menu item to tab and delete pages but tat doesn't work.
Now I have 3 menu items with same name, same link
Update: ok I could delete them by changing the name (the Menu link title) and then doing Reset > they immediately disappeared.
Comment #33
thomasmurphy CreditAttribution: thomasmurphy commentedI had a lot of problem with the menu table in D7 on a very large website with a very large menu which had stopped working because it wasn't managed properly. There were some strange examples items appearing and disappearing, so I finally just connected to the database directly and cleaned it up there. What I did discover was that there were a lot of orphaned menu records which didn't appear in the UI because their parent no longer existed, as per this issue, but if a menu item with a matching name was created they appeared in the UI again. The next time I see anything that weird again I'm going straight to the database.