"exanded" elements of a menu-item-rooted tree aren't expanded

rameshrr - March 11, 2009 - 20:31
Project:Menu block
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Hi,

I have three levels of menu ex.

Top level
Sub level 1 nav1
Sub level 1 nav1 sub
Sub level 1 nav2
Sub level 1 nav2 sub

I only want to expand Top level, and everything else should be collapsed so that it will look like below:

Top level
Sub level 1 nav1
sub level 1 nav2

Is there a way to prevent the menu block from expanding all children and just expand the top level items.

Thanks,
Ramesh

#1

JohnAlbin - March 11, 2009 - 21:15
Priority:critical» normal
Status:active» postponed (maintainer needs more info)

I need to better understand what you want before I can tell you how to do it. :-)

So, what happens when you click on the "Sub level 1 nav1"? Do you want the children to appear at that point? Or do you want it to remain hidden like it is to start?

#2

rameshrr - March 12, 2009 - 17:27

Thanks for the reply,

Yes when I click "Sub level 1 nav1" then the children should appear otherwise it should remain collapsed.

Thanks,
Ramesh

#3

rameshrr - March 12, 2009 - 17:28
Status:postponed (maintainer needs more info)» active

#4

JohnAlbin - March 12, 2009 - 17:42
Status:active» fixed

Ok, so menu_block has the "expand all" checkbox, but you can't "expand only down to the 2nd level".

But…

To get around that, you could edit your menu under admin/build/menu and click the "expand" checkbox for all of the item on the first level that you want expanded. And then just menu_block work normally without its "expand all" feature enabled.

Does that work for you?

#5

rameshrr - March 12, 2009 - 20:47

That is how I have set it up, but it does not work. In the menu block I have the expand all unchecked, and in the admin/build/menu I have set it to expand the 2nd level but not the third level. But the menu block overrides the setting and only allows to either expand all or collapse all.

#6

rameshrr - March 13, 2009 - 13:26
Status:fixed» active

#7

JohnAlbin - March 13, 2009 - 16:55
Status:active» postponed (maintainer needs more info)

I just tested this and it works exactly as I describe. So something is misconfigured on your site.

If you'd like me to help, please provide screenshots of the block config and the menu config pages.

#8

rameshrr - March 13, 2009 - 20:23
Status:postponed (maintainer needs more info)» active

here is the screen shots, Thanks for your help

AttachmentSize
block_menu_setting.png 57.85 KB
admin_menu_setting.png 42.81 KB

#9

JohnAlbin - March 13, 2009 - 22:57
Title:Don't expand all the sub-menus of this tree.» "exanded" elements of a menu-item-rooted tree aren't expanded
Version:6.x-2.2» 6.x-2.x-dev
Component:Miscellaneous» Code
Category:support request» bug report

Ok. I just confirmed this.

I hadn't set the root of my menu block to a specific menu item. If I just use the menu root, things work as expected.

So, this is definitely a bug.

#10

rameshrr - March 16, 2009 - 14:15

Is this something that can be fixed easily, when can I expect a fix for this issue.

#11

JustMagicMaria - March 25, 2009 - 19:05

Having the same issue and would love a fix.

#12

rameshrr - March 27, 2009 - 20:32

I needed this fix but was not able to find a solution, therefore I decide to hack it myself here is the hack if anyone wants to use it make sure you make a backup of your site as this has not been tested, I currently use it and it works fine:

1. Open menu_block.module in a text editor
2. Replace the function called "function menu_tree_depth_trim(&$tree, $depth_limit)" with the following:

function menu_tree_depth_trim(&$tree, $depth_limit) {
// Prevent invalid input from returning a trimmed tree.
if ($depth_limit < 1) { return; }

// Examine each element at this level to find any possible children.
foreach (array_keys($tree) AS $key) {
if ($tree[$key]['below']) {
if ($depth_limit > 1) {
menu_tree_depth_trim($tree[$key]['below'], $depth_limit-1);
}
else {
//This is the hack that I have put in, It checks for active link if so it will expand otherwise it will not
//Hack start
if ($tree[$key]['link']['in_active_trail'] && $tree[$key]['below']) {
// Continue in the subtree, if it exists.
$next_level = $key;
}
else{
// Remove the children items.
$tree[$key]['below'] = FALSE;
}
//hack end
}
}
if ($depth_limit == 1 && $tree[$key]['link']['has_children']) {
// Turn off the menu styling that shows there were children.
$tree[$key]['link']['has_children'] = FALSE;
$tree[$key]['link']['leaf_has_children'] = TRUE;
}
}
}

3. Once that is done go into the admin blocks and in the configure option of your menu block change the "Maximum depth" to the depth that you want expanded and check expand all children. This hack use the "Maximum depth" as the level that should be expanded up to. and if you have levels higher then the maximum depth all it will do is hide the links until the parent is clicked at this point the links are revealed. I am using the menu_block 6.x-2.2, and everything is working as I want it too as described in my initial post.

-Ramesh

#13

cedric - October 20, 2009 - 00:19
Status:active» needs review

Attached is a very simple patcht that simply adds an additional check before trimming a menu tree.

If a menu item has the 'expanded' field ticked in the menu configuration, it will not be trimmed anymore.

I believe this is the proper fix for this issue, but I have only done limited testing.

AttachmentSize
menu_block-398888-13.patch 776 bytes

#14

toodlepip - October 30, 2009 - 12:35

Tried the patch and the code suggestions above. Neither of them seem to work for my menu tree.

I'm wondering if I'm doing something silly. I'm using a primary links menu with all the menus in trees, for example:

Section 1
Section 2
+ Page 1
+ Page 2
+ Page 3 (expanded)
++ Page 1a
++ Page 2a (expanded)
Section 3
...

So when viewing Page 3, I'd like the sub-menu showing Page 2a to be displayed in another block. I can't figure out a way of making this work, so I'm resorting to adding in menu blocks manually.

Also, I've noticed that if more than one section has 'Expanded' selected then the expanded items further down the menu list inherit all the previously expanded items in the breadcrumb. (sorry tricky to explain).

 
 

Drupal is a registered trademark of Dries Buytaert.