In my module's hook_menu(), I got this code:

$items['somepath'] = array(
    'title' => 'Some title',
    'page callback' => 'mymodule_page',
    'access callback' => TRUE,
    'file' => 'mymodule.page.inc',
    'menu_name' => 'main-menu',
    'type' => MENU_NORMAL_ITEM,
    'plid' => 0,
    'weight' => 5
);

Notice that access callback is TRUE.

Then in my tpl.php file, I have

$menu_tree = menu_tree_all_data('main-menu', NULL, 1);
menu_tree_add_active_path($menu_tree);
$tree_output = menu_tree_output($menu_tree);
print drupal_render($tree_output);

This particular setup gives out a Notice: Undefined index: access in menu_tree_output() (line 1028 of C:\dev\myproject\docroot\includes\menu.inc).

When I do a print_r within menu_tree_output to find the $data['link'] without the access, it turns out to be the menu item that I just added, which was causing the PHP Notice. This is the output of print_r:

Array
    (
        [link] => Array
            (
                [in_active_trail] => 1
            )
        ...
    )

Please note that this Notice doesn't appear when I remove the menu_tree_add_active_path line, but I happen to need that line.

Here are the relevant lines from menu.inc:

// Pull out just the menu links we are going to render so that we
// get an accurate count for the first/last classes.
foreach ($tree as $data) {
  if ($data['link']['access'] && !$data['link']['hidden']) {
    $items[] = $data;
  }
}

Adding a check of array_key_exists('access', $data['link']) will make the Notice go away, but this should probably be done as a patch instead of hacking the core. And there's probably a reason why this particular check is there not there in the first place.

Why does that particular menu item lack the access index that is otherwise present in all the other menu items even though I already set the access callback to TRUE?

UPDATE: Removing the last parameter of menu_tree_all_data removes the Notices, but I have absolutely no idea why.

Comments

Jaypan’s picture

https://drupal.org/node/643758

You can move the thread by editing the original post and choosing 'Module Development and Code Questions' as the forum.

Thank you.