I'm getting a bunch of errors when I try to display a menu block on a forum page. I originally thought that this had to do with Advanced Forum, but I disabled that module and I'm still getting errors:

    Notice: Undefined index: hidden in menu_block_tree_output() (line 611 of /var/www/sites/oga2/featuretest/sites/all/modules/menu_block/menu_block.module).
    Notice: Undefined index: has_children in menu_block_tree_output() (line 629 of /var/www/sites/oga2/featuretest/sites/all/modules/menu_block/menu_block.module).
    Notice: Undefined index: href in menu_block_tree_output() (line 643 of /var/www/sites/oga2/featuretest/sites/all/modules/menu_block/menu_block.module).
    Notice: Undefined index: href in menu_block_tree_output() (line 643 of /var/www/sites/oga2/featuretest/sites/all/modules/menu_block/menu_block.module).
    Notice: Undefined index: mlid in menu_block_tree_output() (line 647 of /var/www/sites/oga2/featuretest/sites/all/modules/menu_block/menu_block.module).
    Notice: Undefined index: title in menu_block_tree_output() (line 658 of /var/www/sites/oga2/featuretest/sites/all/modules/menu_block/menu_block.module).
    Notice: Undefined index: href in menu_block_tree_output() (line 659 of /var/www/sites/oga2/featuretest/sites/all/modules/menu_block/menu_block.module).
    Notice: Undefined index: mlid in menu_block_tree_output() (line 665 of /var/www/sites/oga2/featuretest/sites/all/modules/menu_block/menu_block.module).

This appears to be happening because $data['below'] contains some links that have only an in_active_trail variable and nothing else.

Comments

BartK’s picture

Note that I'm not the only site this has happened to... A google search for the error has revealed a cached page with the same issue:

http://webcache.googleusercontent.com/search?q=cache:C3J3Gk4LoyQJ:www.nu...

BartK’s picture

I've got a fix for this that gets rid of the error message.

In menu_block.module, in the function menu_tree_add_active_path, change:

if ($tree_with_trail[$key]['link']['in_active_trail']) {

to

if ($tree_with_trail[$key]['link']['in_active_trail'] && array_key_exists($key, $subtree_pointer)) {

(around line 423)

It looks like the menu_tree_page_data is returning active trail items that aren't actually in the menu, but the function as it stands is assuming that they are.

isaacfreeman’s picture

I add this issue too, on many admin pages. BartK's fix has done the trick.

JustMagicMaria’s picture

Title:Errors in Drupal 7 when using a menu block on a forum page.» Errors in Drupal 7 when using a menu block

Same. Note I changed the issue title since this isn't just on forums. BartK's fix worked for me too.

TimelessDomain’s picture

Status:Active» Reviewed & tested by the community

#2 works.

jras’s picture

#2 worked for me as well.

pjcdawkins’s picture

Version:7.x-2.2» 7.x-2.x-dev
StatusFileSize
new668 bytes

Here's a patch version of BartK's fix in #2.

acrollet’s picture

Patch in #7 works for me, leaving as RTBC.

tjg’s picture

Any chance this patch will be included in menu_block soon?

tim.plunkett’s picture

Status:Reviewed & tested by the community» Needs work
+++ b/menu_block.moduleundefined
@@ -467,7 +467,7 @@ function menu_tree_add_active_path(&$tree) {
+      if ($tree_with_trail[$key]['link']['in_active_trail'] && array_key_exists($key, $subtree_pointer)) {

The array_key_exists() portion should be replaced with isset($subtree_pointer[$key]), see http://php.net/array_key_exists#example-4540

Rory’s picture

@tim.plunkett - I couldn't find the example you were specifically linking to. But I thought this might be it: http://php.net/manual/en/function.array-key-exists.php#87491

It is important to realise that:

  isset($array ['index'])

Does not act the same as:

  array_key_exists('index', $array)

This is because if an array value is set to NULL

$array['index'] = NULL;

Then isset will return FALSE and array_key_exists will return TRUE.

MrHaroldA’s picture

Rerolled the patch with isset() like tim.plunkett suggested.

This patch fixes these notices:

Notice: Undefined index: has_children in menu_tree_depth_trim() (line 610 of /var/www/d7/sites/all/modules/contrib/menu_block/menu_block.module).
Notice: Undefined index: hidden in menu_block_tree_output() (line 646 of /var/www/d7/sites/all/modules/contrib/menu_block/menu_block.module).
Notice: Undefined index: has_children in menu_block_tree_output() (line 664 of /var/www/d7/sites/all/modules/contrib/menu_block/menu_block.module).
Notice: Undefined index: href in menu_block_tree_output() (line 678 of /var/www/d7/sites/all/modules/contrib/menu_block/menu_block.module).
Notice: Undefined index: href in menu_block_tree_output() (line 678 of /var/www/d7/sites/all/modules/contrib/menu_block/menu_block.module).
Notice: Undefined index: mlid in menu_block_tree_output() (line 682 of /var/www/d7/sites/all/modules/contrib/menu_block/menu_block.module).
Notice: Undefined index: title in menu_block_tree_output() (line 693 of /var/www/d7/sites/all/modules/contrib/menu_block/menu_block.module).
Notice: Undefined index: href in menu_block_tree_output() (line 694 of /var/www/d7/sites/all/modules/contrib/menu_block/menu_block.module).
Notice: Undefined index: mlid in menu_block_tree_output() (line 700 of /var/www/d7/sites/all/modules/contrib/menu_block/menu_block.module).

MrHaroldA’s picture

Status:Needs work» Needs review

Forgot to set status to 'needs review'...

pjcdawkins’s picture

#12 works for me

lstoetzel’s picture

#12 works for me

gmclelland’s picture

Patch in #12 worked for me.

pjcdawkins’s picture

Status:Needs review» Reviewed & tested by the community

Still works for me! Marking RTBC.

Note that this issue is for the -2.x branch while there's also a -3.x. It looks like it's fairly trivial to produce a similar patch for 3.x, but let's keep this thread simple until the maintainer responds.

gmclelland’s picture

Sorry, I spoke to soon. The error I see is bit different and doesn't apply to this issue.

ayalon’s picture

Tested and working

Please commit it.

Mirroar’s picture

Confirming that it works for me as well. Thanks for the patch!

jci’s picture

Works for me - thanks! Please commit it.

Cauliflower’s picture

Patch in #12 works as expected.

JohnAlbin’s picture

Title:Errors in Drupal 7 when using a menu block» Fix undefined index notices in menu_tree_add_active_path()
Status:Reviewed & tested by the community» Fixed

Status:Fixed» Closed (fixed)

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