I'm using the menu-block as a primary links sub-menu. For example, what I want is when I click "History" in my primary links bar, a block shows up on the left with "1960-1970", "1980+", etc. and when one of those is clicked, the block should still be there for the different sections of History.

I think I set it up fine as it works perfectly on the History pages and on the "Welcome" page and a few other nodes. But on ONE of my sections, it just doesn't want to work. Example, "Recruitment". I set it all up the same exact way, with the pages "Part 1" and "Part 2" having the parent "Recruitment", exactly like I have it set up for "History". The problem is, when you click "Recruitment" in primary links, the menu-block just won't show up, no matter what I do. If I go through the Administration and click on "Part 1" or "Part 2", then the menu-block will show up on those pages, but again, not if I go up to the main "Recruitment" page.

It just doesn't seem to make sense to me, I don't see what's wrong. Everything is the same from the two sections, yet the menu-block won't show up on the main page of one. What are some ideas to look into? This is really bugging me.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dafeder’s picture

I'm having a similar problem, where it is stuck for a certain path. If I change the path for a page where it doesn't show up, it will appear again, without making any changes to that page. I don't have any block visibility settings for this block. Not really sure how to debug this.

gianfrasoft’s picture

I have the same problem... Did you solve it?

dooug’s picture

Version: 6.x-2.2 » 6.x-2.3

I was experiencing a similar problem. I have a menu block that has a "2nd level (secondary)" Starting Level. And the block does not show for one children, when I visit that child menu link.

What I discovered, which sounds similar to comment #1, when the Parent menu items path is the same path as the first child's menu item path the block will not show up.

For example:
- people/friends
-- people/friends
-- people/family
-- people/neighbors

The people/friends page doesn't show the block. I dug through the menu_block.module file, and discovered that the menu item's 'in_active_trail' variable is FALSE in these cases. And it seems that the menu is already this way when the menu_block module builds its tree. ('menu_tree_page_data' function at line # 412)

So, I am unsure if this bug is in menu_block or in core. maybe menu_block needs to do something tricky with this case that the menu module does do.

sean_a’s picture

I can also replicate- when using the 2nd level starting level, the menu sometimes does not show up on pages. I ended up just deleting the menu and recreating it and it seemed to clear it up.

grasmash’s picture

@#3

I'm experiencing the same issue. When the first child has the same path as the parent, the menu block does not show the children.

This seems like an issue that would arise frequently. Did you find a work around? I'm having trouble figuring out exactly where this code needs to be patched.

grasmash’s picture

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

Hm... I've been trying to find an appropriate fix for a while. He's what I have so far:

added on line 312 of menu_block.module:

  // check to see if any child menu items are identical to parents
  // if so, set active trail correctly
  menu_compare_children($tree);

then added this function:

function menu_compare_children($tree){
  //loop through menu items
  foreach (array_keys($tree) as $key) {  
    if ($tree[$key]['below']){
      foreach($tree[$key]['below'] as $child_key => $child){
        //if menu item has children, compare child paths to this items path
        if ($tree[$key]['link']['in_active_trail'] && ($child['link']['link_path'] == $tree[$key]['link']['link_path'])){
          //if paths match, set child to be part of active trail
          $tree[$key]['below'][$child_key]['link']['in_active_trail'] = TRUE;
        }
      }
    }  
  }
}

I've tried placing this function in a few different places. Calling it from menu_tree_prune_tree() will set the array value correctly, but it doesn't generate the needed ['below'] array.

Not really sure at what point in the module this should be fixed.

grasmash’s picture

After messing about some more, I've decided that this seems to be more of a core issue. To fix this via menu_block, you'd have to generate the ['below'] array for each child menu item that experiences this issue.

I did find a reasonable workaround, which I'll share.

Let's say that you want a menu structure like:
- people/friends
-- people/friends
-- people/family
-- people/neighbors

Now you're basically going to create dummy nodes that will redirect to the desired page. The parent (in menu) will redirect to the child's node.

Method 1:

-Download and install CCK Redirection
-Create a Content Type 'Redirect Node' and add a CCK Redirection field to the content type
-Create a page node (node 1) with URL "people/friends" and add a menu link
-Create a 'Redirect Node' (node 2) and create a menu link for this new node.
--Set CCK Redirection field for to the URL node 1 (people/friends).
-Make node 2's menu item the parent node 1's menu item

Basically you're creating dummy nodes that will redirect to the desired page rather than creating two menu links that have the exact same path.

Method 2:

If you want to get really fancy, you can take a more user friendly approach by combining CCK's Node Reference module with the Rules module.
-Create a Content Type 'Redirect Node' and add a Node Reference field 'field_redirect_target'. Be sure to configure this so that 1) it is required, and 2) users cannot select nodes of type 'Redirect Node'
-Add a new rule via the Rules module
--when content is going to be viewed
--if content is of type 'Redirect Node'
--Redirect to page: [node:field_redirect_target-path]

This method is a bit nicer for users, since it doesn't require them to find the system path for the target node.

Wrote a more formatted post about it here:
http://www.grasmash.com/node/42

alberto56’s picture

Title: Menu-Block not showing up on random pages » Make it possible to display Menu-Block on all pages
Category: support » feature
Status: Active » Needs review
FileSize
3.8 KB

Here is a patch that does the following:

- on the menu block config page, adds a checkbox "Always display all menu items regardless of whether the current page is withing the menu tree".
- if this is checked, the menu tree is generated using drupal's menu_tree_all_data(), not menu_tree_page_data() (that is, the current page is ignored).
- fully tested with simpletest
- no changes to the database
- this patch is designed to be applied safely and not change anything in your module, unless you specify that certain menu_blocks should appear everywhere.

alberto56’s picture

Oops, forgot to add the test files. Here is an updated patch

JohnAlbin’s picture

Issue summary: View changes
Status: Needs review » Closed (won't fix)