Download & Extend

Including parent item in the menu

Project:Menu block
Version:7.x-2.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

How can I extend the functionality to include the parent item in the menu?

If my Primary Links menu is

-Foo1
--Bar1
--Bar2

etc. then setting the menu to Primary Links, the item to and starting level to 2 then when I go to Foo1 the menu is

Bar1
Bar3

when I'd like

Foo1
Bar1
Bar2

This seems to be the way the Druaplcon site works at http://paris2009.drupalcon.org/aboutus - do I have to manually add in an entry for Foo1 to the menu so it's

-Foo1
--Foo1
--Bar1
--Bar2

or is there a better way?

Comments

#1

I couldn't see any way to do that either without setting the block title, which I see as error prone.

Attached is a patch with my solution

Cool module

AttachmentSize
menu_block_show_parent.patch 1.58 KB

#2

Sorry for the newbie question: To which file is the patch supposed to be applied?

#3

hefox,

I tried to implement your patch, but could not get it to work. Instead,

when at

Parent

of

Parent
--Child1
--Child2

all I saw was

--Child1
--Child2

Is there a setting that needs to be set so that only

Parent
--Child1
--Child2

can be seen? I don't want to see all the other Parent links, jut the Parent link that is active, and its children in a sidebar.

Thanks for your help.

#4

Status:active» needs review

I got this patch to work fine (rolled against the current release 6.x-2.2), although needed to check the Expand children: > Expand all the sub-menus of this tree option to get it to work as planned; I also set starting level to '1st with parent' (which is the option the patch adds) and Maximum depth to 2.

This is a really useful addition to menu block and I have suggested that this code should be reviewed. Hopefully this functionality will make it into a future release of the module.

Thanks @hefox

#5

Thanks @hefox

i got this to work perfectly for one of my menus. exactly what i was looking for.

it would be great to be able to choose 2nd level with parent!
anyone know how to do that?

#6

hefox, et. al,

The patch does work, sorry for the confusion. Though, I did misinterpret what I though the patch was going to do.

I am looking for what alburton I think is suggesting by "2nd level with parent."

That is, show a second level link and only the parent it is connected to, not all the other menu items at the parent's level.

For example

If I click on Parent1 (or any of its children), I see:

Parent1
--child1
--child2
--child3

and not

Parent1
--child1
--child2
--child3
Parent2
Parent3
Parent4

#7

Maybe you could use the cool new features in -dev : #345419: Add option for menu title as link.

Since John committed the solution above, I don't think patches in that issue could be committed.

#8

subscribing

edit: the patch worked for me, this is exactly what I needed. It messed with my CSS a little but that can be fixed.

The other thing I just learned about is to use the command line to apply the patch, in my case Terminal in OS X. I took the patch and put it in the same directory as the files to be patched and then used the command:

patch -b < menu_block_show_parent.patch

This saves lots of time. If your site is online and you don't have ssh access you could download the folder with the module to be patched via FTP, make a temp folder on your hard drive and then do the patching and reupload.

#9

Version:6.x-2.2» 6.x-2.3
Status:needs review» reviewed & tested by the community

Just hacked around and re-rolled the patch for 6.x-2.3 (#1 won't work against he latest release). Uses the same code that @hefox worked out and seems to work fine...

I'm not a great patch roller... so it's 2 separate files. (off topic: can the text from 2 sep patches just be merged to create a single file?)

AttachmentSize
menu_block_parent.admin_.patch 523 bytes
menu_block_parent.module.patch 846 bytes

#10

(@snorkeys, yes I've done it a few times (combine patches) XP.

#11

For me, this patch breaks menu items more than 2 levels deep. If I include the parent, the block doesn't show up at all.

Any fixes?

#12

Status:reviewed & tested by the community» needs work

The patch didn't work for me, and a good solution should be to make an 'add parent to menu links' checkbox available on all levels, not just first.

#13

Has there been any progress with this? This seems to be the right direction, but the patch in #9 is not working (for me at least).

#14

This would be a great feature.

#15

Here's a patch against 2.3. Instead of the arbitrary depth limit of 1 in the previous patch, this should support unlimited depth below the parent menu item using the existing level selection dropdown. It just provides a checkbox on the block settings called "Include Parent"...

AttachmentSize
include_parent.patch 5.36 KB

#16

Status:needs work» needs review

setting it to needs review

#17

I've modified stockliasteroids patch a bit to also work for sub menu blocks that don't have a parent menu item selected but only a menu.

AttachmentSize
menu_block.patch 4.74 KB

#18

Believe it or not, but all it took was highrockmedia's reply to start patching for the first time. Other tutorial pages seemed a little overwhelming to me.

Thank you, highrockmedia, for this valuable entry.

#19

Just what I was looking for - thanks. This option should be available by default.

#20

I ported the patch provided in comment #17 (thank you!) to Drupal 7 including some minor improvement, see #1045352: Including parent item in the menu

#21

Version:6.x-2.3» 6.x-2.4
Category:support request» feature request
Status:needs review» reviewed & tested by the community

I've just rolled the patch at #17 against 6.x-2.4 and works (with a few offsets). The patch certainly works, and it seems that there are at least 2 others that have tested it => RTBC.

#22

i can confirm that the patch is working with 6.x-2.4.

attached you can find a re-roll of the patch in #17 which just removes the offset warnings.

AttachmentSize
menu_block_include_parent.patch 4.74 KB

#23

Version:6.x-2.4» 7.x-2.x-dev
Status:reviewed & tested by the community» needs review

I've manually applied the patch from #22 to 7.x version files, and everything seems to be functioning as expected.

AttachmentSize
port_to_v7-476798-23.patch 4.56 KB

#24

Nice to see that it works in 7.x. But was the 6.x-2.4 patch committed? If not can it be left at RTBC and a separate issue for D7 started?

#25

Some time ago, I adapted the patch from comment #17 for D7 with some minor additions (work for menus of arbitrary levels and do not add the parent item as the only item in the menu), see #1045352: Including parent item in the menu. I was asked to to post the patch here, so this is what I do.

AttachmentSize
menu_block_include_parent_d7.patch 6.62 KB

#26

Just tried this patch and it fails test -- menu_block version info listed below as is the fail

Any ideas ??

Thanks

patching file b/sites/all/modules/menu_block/menu_block.admin.inc
Hunk #1 FAILED at 246.
Hunk #2 FAILED at 356.
2 out of 2 hunks FAILED -- saving rejects to file b/sites/all/modules/menu_block/menu_block.admin.inc.rej
patching file b/sites/all/modules/menu_block/menu_block.module
Hunk #1 FAILED at 180.
Hunk #2 FAILED at 196.
Hunk #3 FAILED at 317.
Hunk #4 FAILED at 505.
Hunk #5 FAILED at 516.
Hunk #6 FAILED at 538.
6 out of 6 hunks FAILED -- saving rejects to file b/sites/all/modules/menu_block/menu_block.module.rej

menu_block version:

Project : menu_block
Type : module
Title : Menu Block
Description : Provides configurable blocks of menu items.
Version : 6.x-2.4
Package : Other
Core : 6.x
PHP : 4.3.5
Status : enabled
Path : sites/all/modules/menu_block
Schema version : 6201
Requires : block, menu
Required by : none

#27

Works like a charm!

#28

I reattempted patch and it worked fine this time.

Regards

Mark

#29

Does anyone have a patched version of the D7 menu block module that I can use?

menu_block_include_parent_d7.patch

as I am not able to apply the patch easily myself.

Thanks

#30

mjpg, attached you find the 7.x-2.2 version, patched with my patch from comment #25

AttachmentSize
menu_block-7.x-2.2-patched.zip 43.45 KB

#31

Many thanks - still not quite working but I suspect that it may be the dual language versions of the pages with two menu entries causing an issue.

#32

thank you for this patch! working great.

#33

for #30 to work, I had to set the maximum depth to 2 or more (i had it on 1) otherwise you only see the parent item.

#34

Indeed Yuri, the maximum depth should be set to "2", which leads to the menu being built up in a list within a list.

Is there a way this behaviour doesn't occur? In other words: is it possible to add both the parent item and the subitems in one list?

Here's what I mean:

Currently this is the case:

<ul>
  <li>Parent item
    <ul>
        <li>Subitem</li>
        <li>Subitem</li>
        <li>Subitem</li>
    </ul>
  </li>
</ul> 

Here's what I'd prefer:

<ul>
  <li>Parent item</li>
  <li>Subitem</li>
  <li>Subitem</li>
  <li>Subitem</li>
</ul>

If this isn't possible or if it's bad practice (confusing for SEO), then it's still possible to solve that through CSS layout-wise.

#35

Due to issues from the Drupal 7.12 upgrade it seems that we're forced to upgrade to Menu Block 2.3.
#1425342 Drupal core upgrade from 7.10 to 7.12 causes menu block to fail

I was happily using Ronino's patch at #25

I'm not sure if the Menu Block 2.2 patch will work on Menu Block 2.3?

It would be so great to get the "Include parent" functionality included in Menu Block that this patch provides.

#36

i re-applied Ronion's patch at #25 to Menu Block 2.3 post drupal 7.12 upgrade and all appear to work as expected for me

nobody click here