Here is an error I do not understand:
Undefined index: menu-user-example in menu_tree_build() (line 256 of example.com/public_html/sites/all/modules/menu_block/menu_block.module).

The code at line 249 says:

    if (empty($config['menu_name'])) {
      return array();
    }

The code at 256 says:
menu_block_set_title(t($menu_names[$config['menu_name']]));

We currently have only one menu block and it uses "the menu selected by the page". From what I can see of the error, the menu block might be on a page that is not selecting a menu from the default list. If that is normal, I would expect the code would have something like:

    if (empty($menu_names[$config['menu_name']])) {
      return array();
    }

http://drupal.org/node/1232308 sounds similar but our problem is not a result of an upgrade. The system has too many pages and too much activity to test them one at a time.

The error is made more complex by menu-user-example not appearing anywhere in the database.

I tried to reproduce the error on our test system but could not find the page creating the problem. I might have to add diagnostic code around line 256. Can I trace the error back through the database without adding code?

If I do add code, what variables would tell me the cause of the problem?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

803redman’s picture

gmclelland’s picture

Version: 7.x-2.3 » 7.x-2.x-dev

I believe I'm experiencing the same thing.

Here is the error I get:
Notice: Undefined index: book-toc-14 in menu_tree_build() (line 317 of /home/quickstart/websites/updater.dev/profiles/cmf/modules/contrib/menu_block/menu_block.module).

Steps to reproduce

1. Enable the book module
2. Create a Menu Block with the following settings
--Block Title= Blank
--Menu = <the menu selected by the page>
--Starting level = 2nd level (secondary)
--Make the starting level follow the active menu item = checked
--Starting level will be= Active menu item
--Expand all children of this tree = checked
3. Place the block in the sidebar
4. Goto admin/config/user-interface/menu-block
--Set the "Book navigation" menu available to "checked"
5. Create a new book page
--Select the "Book outline" tab and choose "New Book"
6. Save the node and BAM there's my error.

Note: you can get rid of this error message by clearing the menu cache, but then it comes back every time a new book is created.

Hope that helps. Let me know if you need more info.

JohnAlbin’s picture

The problem is that menu_block_get_all_menus() is over-zealously cacheing the list of menu names. Clearing the cache fixes it.

It's possible implementing hook_menu_insert and hook_menu_delete to clear menu_block's cache will fix the issue.

JohnAlbin’s picture

Title: Undefined index: example in menu_tree_build() (line 256 of menu_block/menu_block.module) » Cache in menu_block_get_all_menus() not updated on menu creation/deletion causing Undefined index error
JohnAlbin’s picture

It's possible implementing hook_menu_insert and hook_menu_delete to clear menu_block's cache will fix the issue.

Actually, the book module doesn't cause those hooks to fire when books are created. blargh.

Dave Reid’s picture

Title: Cache in menu_block_get_all_menus() not updated on menu creation/deletion causing Undefined index error » Cache in menu_block_get_all_menus() not updated on book menu creation/deletion
Issue summary: View changes
Dave Reid’s picture

Status: Active » Needs review
FileSize
1.04 KB

I think this should resolve it.

  • Dave Reid committed fd74dbe on 7.x-3.x
    Issue #1489174 by Dave Reid: Fixed cache in menu_block_get_all_menus()...
Dave Reid’s picture

Status: Needs review » Fixed

Committed #7 to 7.x-3.x and 7.x-2.x.

  • Dave Reid committed 2274415 on 7.x-2.x
    Issue #1489174 by Dave Reid: Fixed cache in menu_block_get_all_menus()...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.