Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Let's say I have a primary menu like this:
- Section 1
- Page 1
- View page
- Page 23
- Section 2
- Page 3
- Page 5
- Page 9
- Third level, page 35
- Page 67
- View Page
- Section 3
I need the ability to trigger a context based on my menu path. For instance if I was on page 9, I should be in context "section 2." Currently, there seems to be no way to do this without custom code or adding specific node ids.
So I envision the menu integration happening like nodequeue or views, pick a menu, and then pick a parent.
Or can I do that now? I'll admit that I haven't tried version 2, since it's code is not recommended on the project page. Thanks for the help everyone!
Comment | File | Size | Author |
---|---|---|---|
#8 | 463898-use-href-not-menu-link.patch | 782 bytes | Damien Tournoud |
Comments
Comment #1
joshmillerRead through some of the other issues and found a common theme: When asked for a specific context trigger, they are often met with "use paths."
I'm going to use pathauto and node hierarchy to generate hierarchical paths automatically.
What's scary about this? Paths are DESIGNED to be flexible and change.
Possible simple solutions:
Just sayin' ...
Comment #2
Pasqualleuse paths
Comment #3
joshmillerIf my contexts are based on paths, then zen does everything I need with the body classes that read "section-parentpath"
It's sad that I can't set context based on where I am in a menu or using taxonomy terms. Seems like this would be a very powerful combination.
Here's the reason I can't use context: I'm using ONE content type (page) that has MANY contexts. Outside of paths or nodequeue, there is no way to determine context. It seems like context solves the big problems of organizing lots of different content into smart groups, but it leaves behind the ability to organize similar content into smart groups.
Hopefully this feature request helps the developers take the next step. Not trying to nag.
Comment #4
joshmillerClarifying the title for others to find...
Comment #5
yhahn CreditAttribution: yhahn commentedHi Josh,
To update you -- you're right that it's not possible to do this currently through the context UI. It should be fairly straightforward to write a menu location context condition to handle this.
If I understand correctly what you need is:
A context condition that sets the context when any of the selected menu items are in the active trail. (Widget would be a menu tree with checkboxes or multiselect?)
Re: taxonomy, there is a patch in the queue that I have regretfully not reviewed yet: http://drupal.org/node/343110. Feel free to try it out and let me know how it works out for you.
Comment #6
joshmillerAbsolutely what I need: "A context condition that sets the context when any of the selected menu items are in the active trail." This would solve part of my problem, the other part seems to be met by the patch in the other issue!
Thanks! I think context makes blocks make sense and am delighted that this is on the roadmap.
Josh
Comment #7
yhahn CreditAttribution: yhahn commentedI've committed a menu trail based context condition to DRUPAL-6--2. I'd love to get your testing/feedback before the next release.
http://drupal.org/cvs?commit=216554
Comment #8
Damien Tournoud CreditAttribution: Damien Tournoud commentedNice patch. That was the only feature I was missing before actually using context ;)
link_path
is generally not available in the menu trail, because the menu item is not always loaded. This is for example the case for menu links created from placeholder-based menu routers.We have you use
$item['href']
for this, patch attached.Comment #9
yhahn CreditAttribution: yhahn commentedAwesome. Committed: http://drupal.org/project/cvs/64885
Comment #11
markabur CreditAttribution: markabur commenteddoes this feature actually work?
i have the same situation as the OP but the context only gets set if i'm actually on the page that i based the context condition on -- if i'm on one if its children then the context does not get set. iow if i base the context condition on "section 2" then if i'm on "page 9" or "page 67" then the context is not set, even though the "section 2" menu item does in fact get the active-trail class when the page is rendered. the only way to get the context to be triggered on the child pages is to add them in to the condition as well. which means that the context definitions need to be updated every time my client adds a page to the site..
so, drupal somehow is correctly figuring out what the active trail is, but context module is apparently not using the same criteria. i've dug in a bit and found that menu_get_active_trail() only returns <front> and the current node, rather than the actual active-trail menu items, so i'm curious why anyone thought this patch solved the problem described by the OP.
Comment #12
petebarnett CreditAttribution: petebarnett commentedmarkabur,
I'm having exactly the same problem. Context is only set when you are viewing the page itself... Anyone managed to get round this? I'll have a look and let you know what I find.
Thanks,
Peter
Comment #13
petebarnett CreditAttribution: petebarnett commentedOk i've worked out what the problem is...
menu_get_active_trail()
only works on the currently active menu, which by default is "navigation".If your page isn't in this menu, then the trail will just be a default of <front> and the current node.
If I call
menu_set_active_menu_name()
with my custom menu, the active trail is then returned correctly, and everything else works correctly.The active menu influences more than just Context conditions though, and I'm wondering if some other solution exists for setting this?
There is a module that does this for breadcrumbs (http://drupal.org/project/menu_breadcrumb), and I've temporarily hacked
context.core.inc
to use the same method to get the menu that the current page belongs to.This could be a solution, or maybe the user could select the menu to work with in the context UI?
Peter
Comment #14
Damien Tournoud CreditAttribution: Damien Tournoud commented@peterbarnett: I see no reason why menu_breadcrumb doesn't set the active trail of the page instead of just the breadcrumb (it really seems dumb). Please open a bug report against menu_breadcrumb to do that, and it will magically make the active trail context work with all the menus.
(It's just not Context job to define what the active trail is.)
Comment #15
petebarnett CreditAttribution: petebarnett commentedHi Damien,
It just calls
menu_set_active_menu_name()
, which does make the active trail context work, but I guess not everyone is using the menu_breadcrumb module, and it's not a dependency of Context.I actually ended up implementing a tiny (3 line) module with a
hook_init()
implementation that does exactly what menu_breadcrumb does on all pages.I guess context allows the user to select any menu item as a trigger for the active trail condition, but in reality, only menu items from "navigation" are normally going to work (unless you're on the selected page itself).
I agree that it's not necessarily context's job to define what the active menu is, but there's definitely something missing in how the complete setup works.
Peter
Comment #16
markabur CreditAttribution: markabur commentedi've been using menu_breadcrumb simply to get around the menu_get_active_trail() problem and it works fine... though i'm going to switch to using hook_init() as i have a custom module anyway, and don't need menu_breadcrumb for anything else.
Comment #17
haggins CreditAttribution: haggins commentededit: wrong usage
Comment #18
haggins CreditAttribution: haggins commented