0

To my surprise, I removed one menu item from the main menu, and it correctly dissapeared from the admin ui, but there still is an entry in the table called menu_links. There is nothing unusual about the entry. How does drupal know it should not be used ? Can I manually remove it ?

The problem is, I use custom code that traverses the menu_links table to generate an alternative menu. This custom code just sees the menu item and keeps on displaying it in the alternative menu. So, is that approach wrong ?

1

The menu_links table contains a lot of automatically generated rows. These come from the hook_menu() implementation of modules. Deleting these rows will likely result in them returning on the next time you clear the cache, because menus will be rebuilt than and the systems scans through all hook_menu() implementations adding new links.

If you look closely at the menu_links table, you'll notice there is a boolean field hidden. A value of 1 tells Drupal not to show this item in menu's.

So you can either filter out all hidden items (you only need hidden = 0 since the value -1 represents a menu callback), or you can have a look at the Drupal menu functions. There are a lot of functions with menu and tree, but if I am not mistaken you are looking for menu_build_tree.

5
  • Thanks for responding. In the menu_links table, for the 'removed' item, the module is 'menu' and hidden is '0'. Its totally the same as its (former) sibling menu items, which have not been deleted. So that's not what the admin ui seems to be looking at. – commonpike Dec 29 '16 at 11:22
  • Maybe I misunderstood, you totally removed an item you created manually and did not toggle the visibility checkbox? Then you might attempt to delete it (make a backup and check your logs afterwards for weird errors). A safer approach would be to manually change the hidden field to a value of 1 and slightly change your query. That will never break anything. – Neograph734 Dec 29 '16 at 11:27
  • yes, totally removed it from the admin menu. i expected it to be removed from the menu_links table (since its a item generated by the menu module), would you agree that that should have happened ? – commonpike Dec 29 '16 at 14:39
  • I solved this particular issue by using some of your suggestions, and did not delete the menu_links entry. but I think your answer suffices for future users, so I'll except it. thanks! – commonpike Dec 29 '16 at 14:40
  • 1
    would you agree that that should have happened? I don't know if it should have happened. Perhaps Drupal has a mechanism in place that performs the actual delete later in order to prevent loading the table. But I would have expected it to be deleted, yes. – Neograph734 Dec 29 '16 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.