In Drupal 4.6.0 I tried writing something similar to module taxonomy_menu so that I can insert extra menu items using a different data source. I read the documentation for hook_menu but it does not mention how it uses caching or the menu table. My use of hook_menu produced something different to taxonomy_menu.

Some of the added items never appeared in the menu no matter what I did. I tried MENU_DYNAMIC_ITEM but nothing changed.

I then shut down the computer for a rest (I have a strict rule of spending at least 0.5 hours a day away from the computer). This morning some extra menu items appeared. What changed?

Last night I tried clearing the cache table but that did nothing. I tried resetting the menu table but that did nothing. I tried my code in the $may_cache is true section and in the false section. There must be something else stopping the menu items displaying.

I found the menu items were appearing in the menu table with settings that are exactly the same as menu items that display. When I visit administration >> menus I found some of the temporary menu items from my code were being added to the menu table. After a few visits to the menus page I have items added seven times.

The extra entries have a pid of 1. pid is the index of url_alias but there is no entry in url_alias with pid=1.

The extra entries are of type 22 and I have not found where the type field is defined or used.

I would like to add extra menu entries and hook_menu seems like the right place. The extra entries may occasionally have the same name or link as the existing entries. I do not mind if they are cached or not. Initially my code will run for every page and I can test my code faster if nothing is cached. Once the code is working, I would like it to check entries when nodes are added so that I can add an extra value from the content creation page. taxonomy_menu looks like the perfect role model.

If I use MENU_DYNAMIC_ITEM should it be in $may_cache true or false?

I do not see any change when using MENU_DYNAMIC_ITEM? What does MENU_DYNAMIC_ITEM do?

Comments

peterx’s picture

I found that to add menu item Abc, I had to empty the cache table and delete every row in menu table for Abc. It appears that Abc was added as permanent before I discovered MENU_DYNAMIC_ITEM. I have to delete Abc to get Abc MENU_DYNAMIC_ITEM to work. Once Abc is added by any means, subsequent additions of Abc create duplicate entries. Why does my code add duplicate entries while taxonomy_menu does not create duplicate entries? How do I tell hook_menu to reuse the entry instead of creating a duplicate?

peterx’s picture

$may_cache true, MENU_NORMAL_ITEM, access true
This combination adds the menu item to the menu if there is nothing of the same name in the menu table. It does not duplicate the entry if there is nothing of the same name. If you add something of the same name then it duplicates the entry and leaves the duplicate in the table.

$may_cache true, MENU_DYNAMIC_ITEM, access true
This combination works exactly the same as the previous combination. Perhaps MENU_DYNAMIC_ITEM does nothing when $may_cache is true.

$may_cache false, MENU_NORMAL_ITEM, access true
This combination sometimes displays the menu item and sometimes does not. The item appears in the menu if you are in the regular menu but not if you are in the administration area.

$may_cache false, MENU_DYNAMIC_ITEM, access true
For this mixture the item will appear in the menu provided there is nothing of the same name in table menu or the cached menu.

peterx’s picture

Menu on-the-fly does most of what I want so I switched from taxonomy to Menu on-the-fly.

Menu on-the-fly was not listed for Drupal 4.6.0 when I first downloaded 4.6.0. The 4.6.0 version appeared after I started trying to use taxonomy. A recent patch to the 4.6.0 Menu on-the-fly makes Menu on-the-fly do enough that I do not need the taxonomy module. I will make menu changes using Menu on-the-fly, add a few extra entries manually using the normal menu module, and wait for 4.7.0 before trying new code.