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 < root of Primary links > and starting level to 2 then when I go to Foo1 the menu is

Bar1
Bar2

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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hefox’s picture

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

marcushenningsen’s picture

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

cvaughn13’s picture

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.

snorkers’s picture

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

abelb’s picture

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?

cvaughn13’s picture

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

GuillaumeDuveau’s picture

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.

Danny Englander’s picture

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.

snorkers’s picture

Version: 6.x-2.2 » 6.x-2.3
Status: Needs review » Reviewed & tested by the community
FileSize
846 bytes
523 bytes

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?)

hefox’s picture

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

jtidal’s picture

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?

FreddieK’s picture

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.

garryi’s picture

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).

jim22’s picture

This would be a great feature.

stockliasteroid’s picture

FileSize
5.36 KB

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"...

hefox’s picture

Status: Needs work » Needs review

setting it to needs review

christiaanb’s picture

FileSize
4.74 KB

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.

knalstaaf’s picture

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.

knalstaaf’s picture

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

Ronino’s picture

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

robcarr’s picture

Version: 6.x-2.3 » 6.x-2.4
Category: support » feature
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.

dgsiegel’s picture

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.

safetypin’s picture

Version: 6.x-2.4 » 7.x-2.x-dev
Status: Reviewed & tested by the community » Needs review
FileSize
4.56 KB

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

robcarr’s picture

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?

Ronino’s picture

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.

mmcintosh’s picture

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

FreddieK’s picture

Works like a charm!

mmcintosh’s picture

I reattempted patch and it worked fine this time.

Regards

Mark

mjpg’s picture

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

Ronino’s picture

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

mjpg’s picture

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.

rbishop’s picture

thank you for this patch! working great.

Yuri’s picture

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.

knalstaaf’s picture

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.

mlecha’s picture

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.

rbishop’s picture

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

iknowbryan’s picture

Menus disappear when you set the "Fixed parent item" to something more than one level deep
(If I start one level deep things are fine)
I'm on drupal 7.12 and menu_block 2.3 and have applied the #25 patch without errors

Any ideas??

e.g. of what I'm after

PARENT ITEM
- PARENT ITEM TWO
-- PARENT ITEM THREE ( I want to start here)
-- ITEM
-- ITEM
-- ITEM
-- ITEM

I'd like to create a menu block that looks like
-- PARENT ITEM THREE
-- ITEM
-- ITEM
-- ITEM
-- ITEM

Anonymous’s picture

I'm on drupal 7.14 w/ menu_block 2.3 and the patch from #25 seems to work perfectly for me.

Looks like this issue has been going on for a while - any way we can get this feature into a release? Is there anything blocking its inclusion?

alexverb’s picture

Status: Needs review » Reviewed & tested by the community

I'm on 7.15 and Menu Block 2.3 and also confirm this patch is working great for me. It would be nice indeed to have this feature in the future release.

hkirsman’s picture

Patch #25 worked for me (using 2.3). This should be included in the module!

Matthew OMalley’s picture

+1 please approve and release

rylowry@gmail.com’s picture

#25 worked for me using menu_block 7.x-2.3.

Katy J’s picture

Thank you. Patch in #25 worked perfectly for me with 7.x-2.3 once I remembered how to apply a patch using the cmd line rather than cut and paste!

hkirsman’s picture

Will this be included into the module?

gmclelland’s picture

How is everyone applying this patch from #25?

I have tried many different variations:
patch < menu_block_include_parent_d7_0.patch
patch -p1 < menu_block_include_parent_d7_0.patch
patch -p0 < menu_block_include_parent_d7_0.patch
git apply -v menu_block_include_parent_d7_0.patch

Nothing seems to work

Ronino’s picture

gmclelland, from what directory did you try to apply the patch?

gmclelland’s picture

@Ronino - Thanks for the reply. I tried running those commands from the root of the module.

Here is a untested manual reroll of #25 that should apply against MB 2.3.

Hope it helps someone.

othermachines’s picture

Here's a new patch rerolled against 7.x-2.x-dev and tested on Drupal 7.23.

Anyone who (like me) is eager to have this feature committed should install 7.x-2.x-dev, test this patch and report back. It's a good feature.

Re comment #37 - also tested on a menu block starting on third leve; works fine.

Thanks everyone.

othermachines’s picture

Status: Reviewed & tested by the community » Needs review
tchopshop’s picture

After patching this I am getting this Notice:

Notice: Undefined index: include_parent in menu_tree_block_data() (line 284 of /profiles/panopoly/modules/contrib/menu_block/menu_block.module).

othermachines’s picture

@tchopshop

Sounds like it may not have applied properly to menu_block.admin.inc. Which patch and which version of menu_block?

tchopshop’s picture

the patch from #48 and the current dev. I applied the patch manually.

othermachines’s picture

@tchopshop -

If you've applied the patch manually, it's difficult for me to troubleshoot. As you can see from the error, $config['include_parent'] is undefined. If the patch was applied properly, this index should be defined in the function menu_block_get_config(). The only other thing I might suggest is that, if you already have a menu block defined, then you may need to resave your block configuration. Let us know if you make any progress.

caschbre’s picture

Issue summary: View changes
Status: Needs review » Needs work

We're running into the same issue as #37. If our parent is at the top of the menu then it works great. However it our parent (as designated in the menu block config) has a parent menu item of it's own, then it returns nothing.

The issue seems to be stemming from the logic inside menu_tree_prune_tree...

+          if (!empty($include_parent)) {
+            $tree = array($key => $tree[$key]);
+          } else {
+            $tree = $tree[$key]['below'] ? $tree[$key]['below'] : array();
+          }

If I were to comment out the if condition and just use...

$tree = $tree[$key]['below'] ? $tree[$key]['below'] : array();

... the menu block renders a menu, though without the parent. It's when we reset the $tree to the parent item instead of the children ('below') that the logic check of

if ($tree[$key]['link']['mlid'] == $plid) {

fails and we eventually hit the !$found_active_trail condition which wipes out any results.

I'm still debugging to figure out why... but i've narrowed it down to that part of the patch that seems to be the cause of the issue.

caschbre’s picture

Status: Needs work » Needs review
FileSize
7.39 KB

Attached is a new patch which is just a small modification to the patch in #48. I've tested this against 7.x-2.x and 7.x-2.3 locally. I did have to manually apply the patch to 7.x-2.3.

Difference between the two patches is small...

#48: if (!empty($include_parent)) {
#55: if (!empty($include_parent) && $plid != $parent_item['plid']) {

This solved the issue we were experiencing noted in comment #37 above.

othermachines’s picture

Brilliant. The patch is good and solves the problem described in #54.

I SO want to mark this as reviewed and tested but I suppose we should wait for one or two others to chime in.

Thanks, @caschbre!

wooody’s picture

Issue summary: View changes
wooody’s picture

Issue summary: View changes
wooody’s picture

Hi,
How can I make the same with Better Jump Menus module...
https://drupal.org/project/jump_menu

Thanks..

othermachines’s picture

@wooody

Go to the Better Jump Menus issue queue and post your question there.

4kant’s picture

Hi there,
I needed a special background color for a menu block when it´s parent item is active (li.active-trail).
With the patch from #55 I could do that.
In CSS i had to set diplay:none for the parent li-item and for it´s sub-items I set diplay:block.
But with the presence of the selector "li.active-trail" of the parent item, I can now style the block.
Thanks!

othermachines’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @4kant. I think this qualifies as reviewed and tested. I checked and no re-roll is required.

jessehs’s picture

The patch in #55 is working for me. It does not apply against 2.3, but it does apply against Dev. (I tested against revision 8dd19f03.)

phai’s picture

The patch #55 is working for me too (REMEMBER: it applies only on DEV).
Thanks

ZenDoodles’s picture

This patch works for me. Testing in a fresh install, using the following steps:

  1. Install as normal. Ensure menu_block is enabled.
  2. Enable devel and devel_generate. (This makes it easier to create a menu tree without manually creating a bunch of menu items: "drush en devel devel_generate"
  3. Generate some content: "drush generate-content 50" to generate 50 pieces of content.
  4. Generate menu items: "drush generate-menus 1 20 9" (Parameters are weird, but that's 1 menu, 20 links, and a max-depth of 9)
  5. Add and configure menu block for the generated menu at admin/structure/block
  6. Observe the block in it's natural habitat.

A couple of minor code comments:

  1. +++ b/menu_block.module
    @@ -199,17 +199,18 @@ function menu_block_get_all_menus() {
    +    'delta'          => $delta,
    +    'menu_name'      => 'main-menu',
    +    'parent_mlid'    => 0,
    +    'parent'         => '',
    +    'title_link'     => 0,
    +    'admin_title'    => '',
    +    'include_parent' => 0,
    +    'level'          => 1,
    +    'follow'         => 0,
    +    'depth'          => 0,
    +    'expanded'       => 0,
    +    'sort'           => 0,
       );
    

    This also needs to be updated in hook_menu_block_blocks() in menu_block.api.php

  2. +++ b/menu_block.module
    @@ -592,8 +596,12 @@ function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE) {
    +          } else {
    

    Sorry this is so nitpicky... We prefer closing braces on their own lines.
    @see https://drupal.org/coding-standards

  3. +++ b/menu_block.module
    @@ -616,8 +624,14 @@ function menu_tree_prune_tree(&$tree, $level, $parent_item = FALSE) {
    +        } else {
    

    Here too. (Still nitpicky)

othermachines’s picture

phai’s picture

Ehmmm.... but it's just a my theory... or updating module to 7.x-2.4 (released today) this behaviour is still unfixed?

othermachines’s picture

Darn. Yeah, looks that way.

jackhutton’s picture

just updating to 7.x-2.4 and notice there's no toggle to 'show parent'.
I reran the patch in #66 which brought back my parent item onto the menu blocks

othermachines’s picture

@jackhutton - If you apply a patch, you have to keep applying it with every update until the patch is committed.

janchojnacki’s picture

Thanks for the patch, othermachines

There is part to remove the only item from the tree if it is the parent item configured to be included. But in my case it was needed to include the only item in the tree, so I a bit extended your patch to make removal of the only item optional.

brad.bulger’s picture

this is a reroll of the patch from #66 against the current 2.x branch. i didn't include the extra feature from #71 only because i haven't used it.

othermachines’s picture

Re-rolled patch in #72 tests OK and applies cleanly. I think it's ready to commit. Thanks @brad.bulger.

@janchojnacki - Please apply the patch in #72 to latest -dev, then create a new patch with only your changes. Post it as a separate issue and indicate that it is dependent on #72 patch being applied/committed first. Thanks!

Pol’s picture

This patch is working perfectly on 7.x-2.x. Can't wait to see this in.

othermachines’s picture

@janchojnacki - Might be a good fit for your patch? Issue #2368805: Show always fixed parent item

caxy4’s picture

+1 for getting this included in 7.x-2.x. Please include ASAP!!!

perlgal’s picture

Hi

I applied the patch in #72 against the latest dev version and it works, but I have the same issue as mentioned in #37 and then revisited in #55 with a patch, that does not work on the latest dev with patch in #72.

Any suggestions will be helpful.

Thanks!

othermachines’s picture

Hi, @perlgal.

I have the same issue as mentioned in #37...

Can you be more explicit about your problem so that we can try to reproduce? I've confirmed that the fix introduced in #55 is included in #72 patch.

Please include your menu block settings.

perlgal’s picture

@othermachines Thank you for the quick reply!

Menu block for Submenu B
The starting level is 1st level primary
Include parent is checked.
Maximum Depth - Unlimited
Expand all children of this tree is checked.
Fixed parent item is

Works for
-Primary Item A
--Submenu B -> Works for submenu B

Does not work for
-Primary Item A
--Sub Menu A2
---Sub Menu B (under A2) -> Does not work. No menu displayed at all.
I hope this explains my issue. Thank you!

othermachines’s picture

@perlgal - It helps, thanks! To clarify, in both examples "Submenu B" is the fixed parent item?

perlgal’s picture

Yes. Submenu B is the fixed parent item.

othermachines’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for catching that, @perlgal. I was able to reproduce the problem with your settings.

othermachines’s picture

So here's the problem...

When iterating over a fixed item's ancestors (p1, p2, p3...), if the fixed item starts at level 3 (or greater) it will always pass this condition on first iteration:

if (!empty($include_parent) && $plid != $parent_item['plid']) {
  $tree = array($key => $tree[$key]);
}

This is because the fixed item's immediate parent will never be equal to its first ancestor ('p1').

So if our tree looks like this:

1.1 <-- p1
.. 2.1 <-- p2
.. .. 3.1 <-- fixed item
.. .. .. 4.1
.. .. .. 4.2

The fixed item's immediate parent is 2.1. Let's iterate through its ancestors...

1.1 <-- p1

This doesn't match fixed item's immediate parent, so start the tree here. Wrong, wrong, wrong. Next iteration...

.. 2.1 <-- p2

It matches! But damn, already too late. We've messed up the trail. And what happens when we mess up the trail?

if (!$found_active_trail) {
  $tree = array();
  break;
}

Yep, that means no menu.

I ran out of time to implement a fix, but maybe someone else will get to it before I do.

othermachines’s picture

Status: Needs work » Needs review
FileSize
6.46 KB
1.31 KB

This patch also checks against the depth of the fixed item.

Melissamcewen’s picture

Patch from #84 works great for me

darvanen’s picture

#84 works for me, even when applied to current stable version (7.x-2.6)

perlgal’s picture

Thank you, @othermachines! The patch from #84 works on 7.x-2.6

othermachines’s picture

Thanks everyone. I've retested against latest -dev. I wouldn't mind one more tester before marking RTBC.

bendev’s picture

Status: Needs review » Reviewed & tested by the community

Just tested it and could make it work withtout any issue...

thanks

The last submitted patch, 1: menu_block_show_parent.patch, failed testing.

The last submitted patch, 9: menu_block_parent.module.patch, failed testing.

The last submitted patch, 15: include_parent.patch, failed testing.

The last submitted patch, 9: menu_block_parent.admin_.patch, failed testing.

The last submitted patch, 17: menu_block.patch, failed testing.

The last submitted patch, 22: menu_block_include_parent.patch, failed testing.

The last submitted patch, 23: port_to_v7-476798-23.patch, failed testing.

othermachines’s picture

That was weird. The actual last submitted patch still passes.

dureaghin’s picture

The patch from #84 not working on 7.x-2.7.

Notice: Undefined index: include_parent in menu_block_configure_form() (line 317 of /sites/all/modules/contrib/menu_block/menu_block.admin.inc).

othermachines’s picture

@Hakintosh - This should really be applied against 7.x-2.x-dev but I did apply it against 7.x-2.7 with no issues. Did your menu_block.module file get patched? The only way the notice makes sense to me is if menu_block_default_config() didn't get updated to include the 'include_parent' key.

rkent_87’s picture

#84 works for me on 7.x-2.x-dev albeit with whitespace warnings when applying the patch

Edit: Actually, does this option include a permissions check or something? When I enable it the menu block is hidden on pages I have set to be visible to authenticated users only.

othermachines’s picture

FileSize
6.32 KB

Well, that's annoying. Here's a re-re-reroll. Thanks @rkent_87.

thtas’s picture

The patch in #101 applies against 2.7 just fine.

Still get the errors as in #98 though because i had existing configured menu_blocks from before the patch.

JKingsnorth’s picture

bradallenfisher’s picture

I just applied patch in 101, checked the box include parent, cleared the cached like 5 times, and nothing happend. The parent is still not included when there is only one menu item.

The patch did apply cleanly against 2.7, it just isn't doing what it is supposed to.

othermachines’s picture

@bradallenfisher - Can you provide more info about your menu block configuration and the expected vs actual output?

bradallenfisher’s picture

Sure.

I have a menu block.
Menu = Main Menu
Include parent is checked
Maximum Depth = unlimited
expand all children is checked
fixed parent item is an item that doesn't have any children

I was under the impression this patch would show the parent item if there wern't any child items.
I have assigned the block to footer and only when I nest menu items under the parent does the block show.

Thanks.

knalstaaf’s picture

Applied patch #101 to the latest dev (2015-Oct-12), but now it only seems to display the parent (not accompanied by its children).

This is how my main menu looks like:

  • Home
  • About
    • Item 1
    • Item 2
    • Item 3
  • Contact

The menu block I'm looking for is this:

  • About
  • Item 1
  • Item 2
  • Item 3

But what I'm getting is this:

  • About

This is my configuration:

  • Menu: main menu
  • Starting level: first level
  • [v] Include parent
  • Maximum depth: unlimited (to make sure)
  • [v] Expand all children (to make sure)
  • Fixed parent item: -- About
othermachines’s picture

Status: Reviewed & tested by the community » Needs work

@bradallenfisher

Thanks for the info. I was able to reproduce the problem.

othermachines’s picture

@knalstaaf

Thanks for the detailed report; however there is some detail missing since I am unable to reproduce your problem on a fresh install with latest -dev.

By the way, what you should be getting with those settings (and what I am getting) is this:

  • About
    • Item 1
    • Item 2
    • Item 3

(This feature doesn't flatten the menu.)

othermachines’s picture

Status: Needs work » Reviewed & tested by the community

@bradallenfisher

This is actually by design.

The idea is to *include the parent in the menu*. It actually says in the description "The parent is not included if it was the only item in the menu." The wording isn't the best (it really should say "has no children" (or better) "if the starting level contains no items"), but you get the idea.

Feel free to convince me that the parent should be included in this case (I'm not 100% certain either way). In the meantime I'm setting this back to RTBC.

bradallenfisher’s picture

I see. I always just use title as link if I want the parent included. It's under the advanced settings if you don't explicitly set a title.

My use case is if you have multiple menu blocks that you use to create a super footer and you want it to mirror your main menu. Everything is fine if all of your visible main menu items have nested items. If one or two don't then the menu block you create for that section isn't available. And you have to manually create the blocks with one link in them. So it's now not dynamic.

othermachines’s picture

@bradallenfisher

Curious: why multiple menu blocks for a single menu? One for each top level section/page? Is it that you want to show only a particular section at a time, depending on active page? (This is pretty typical for sidebar submenus but when I think of a super footer I think of a fully expanded menu that doesn't change.)

bradallenfisher’s picture

Good question! The requirement was that only 2nd level items (with parent item as header) be shown in columns in footer region matching parent items in top nav.

The way I read this issue (feels a little like i high jacked at this point) was that if you have a menu like

Parent 1
--child
Parent 2
-- child
Parent 3
Parent 4
--child
--child

that Parent 3 would be visible as a header item linking to its page.

That way in the future if someone adds items to it they just appear and you also have the same structure as the top menu.

All this is making me think we need a configurable super footer module now. ;)

Cause yeah its stupid adding 6 menu blocks to sitewide context.

Thanks.

othermachines’s picture

@bradallenfisher

Hijacked - No, I actually think you've brought up a good question. Whether you meant to or not. :)

A common use case for a menu block is a sidebar submenu. Let's say we're in the ABOUT section. What this patch does (following this example, anyway) is it allows you to display this:

ABOUT
.. History
.. Press
.. Background

instead of this:

History
Press
Background

Now, when you scoot over to the CONTACT section, which doesn't have any children, you would see this:

 

Yep,.. nothing.

Without the parent displaying there, it seems inconsistent to me. Anyway, I'll leave it as-is for now and see if anyone else wants to chime in with an opinion.

As for your super footer, you could use a single menu block to print out the whole menu, then theme the mark-up to achieve a columnar display. Theming menus is kind of a pain in Drupal, but I do know a few tricks. Use my contact form if you want some help.

Good luck!

bradallenfisher’s picture

Cool thanks!

knalstaaf’s picture

@othermachines: I'm using a flyout-menu workaround for the Bootstrap theme, which hides subitems by default (.dropdown-menu). I'll find a way around this.

There's also this Bootstrap issue: #1850194: Add support for menu block module

othermachines’s picture

@knalstaaf - Yes, I was going to suggest you look at that issue. What you report definitely isn't a Menu Block problem.

JohnAlbin’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

This module already has a "Block title as link" option which replaces the block title with the parent menu item, including its link.

To me, that already-implemented feature looks like a duplicate of this proposed feature. Feel free to re-open if you have an explanation of why this patch is needed.

sumachaa’s picture

we have 4 level menu items, when click on the 4th level menu item; is there a way to bring the parents starting from level 1 itself?

example:

level1
--level2
----level3
------level4_1
------level4_2
------level4_3

When selecting any menu is 4th level, need to bring all the parent items; please let us know if this is possible & how

C13L0’s picture

@JohnAlbin

"Block title as link" only works when the title isn't overridden. In my case, I have to override the title due to the theme/design elements. Also, the design does not allow for -any- block titles to be links. This is exactly what I needed to correct the issue.

The patch in #101 works perfectly. Thanks!!

othermachines’s picture

Status: Closed (duplicate) » Needs review

@JohnAlbin

Thanks for your attention to this. Although there may be some common use cases, replacing the block title isn't the same as including the parent in the menu, particularly from a themer's point of view. That there are 55 followers of this issue including a dozen-ish contributors reinforces that, I think.

othermachines’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC,

agileadam’s picture

#101 worked great for me. Thanks!

glass.dimly’s picture

I'd love to see an 8x version of this patch.

glass.dimly’s picture

Version: 7.x-2.x-dev » 8.x-1.x-dev
FileSize
4.26 KB

Well, it doesn't look like this is going to get included in the 7x version.

However, the 8x version no longer has a "Block title as link" option, which is the reason @JohnAlbin gave for not wanting to include this functionality.

In my opinion, using "Block title as link" instead of rendering the parent menu item is a hack, because when the parent menu item link path or title changes, the block title link does not change. And also a different, non-menu method must be used to translate the block title.

So I've created a patch against the D8 version for this functionality.

Note: There was no good way to craft conditionals for the parameter object to include parent item in the tree (I think this is an oversight in the Drupal core menu code), so I retrieved the entire tree and searched it.

glass.dimly’s picture

Status: Reviewed & tested by the community » Needs review
glass.dimly’s picture

I've updated the patch with minor UI changes to match the rest of the interface.

glass.dimly’s picture

Updated the patch again to catch some errors.

Albert Volkman’s picture

@glass.dimly your patch is causing the top most ancestor to render, not the immediate parent.

Albert Volkman’s picture

Reworked the above patch to traverse all parts of the menu tree.

Albert Volkman’s picture

After working through this... it seems this patch does the same thing, but much simpler-

#2884514: Add option to render 'fixed parent item' menu link

justcaldwell’s picture

Also consider #3082445: Add option to always render parent menu item, which is a reworked version of #2884514: Add option to render 'fixed parent item' menu link that should work with settings other than 'fixed parent item'.

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
Checking patch src/Plugin/Block/MenuBlock.php...
error: while searching for:
      '#description' => $this->t('Alter the options in “Menu levels” to be relative to the fixed parent item. The block will only contain children of the selected menu link.'),
    ];

    $form['style'] = [
      '#type' => 'details',
      '#title' => $this->t('HTML and style options'),

error: patch failed: src/Plugin/Block/MenuBlock.php:57
error: src/Plugin/Block/MenuBlock.php: patch does not apply
komalk’s picture

Status: Needs work » Needs review
FileSize
4.57 KB

Re-rolled the patch

Status: Needs review » Needs work

The last submitted patch, 134: 476798-134.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pameeela’s picture

Status: Needs work » Closed (duplicate)

This seems to be a duplicate of #3082445: Add option to always render parent menu item and although we usually keep the older issue open, that issue has a green patch and is RTBC so I'm going to close this one instead.

apemantus’s picture

Issue summary: View changes