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.
I added one context and Active menu for that context but It is not working
Comment | File | Size | Author |
---|---|---|---|
#61 | context-changes_in_menu_and _breadcrumbs_reactions.patch | 7.06 KB | Arnion |
#41 | context_active_menu_item-586396-41.patch | 703 bytes | grndlvl |
#39 | context_active_menu_item-586396-39.patch | 1.01 KB | grndlvl |
Comments
Comment #1
ceardach CreditAttribution: ceardach commentedConfirmed. I set my context to do two reactions: set the active menu item, and display a block. The block appears appropriately and the context devel block says I am in that context, however, the menu item I selected is not active.
Comment #2
ashiwebi CreditAttribution: ashiwebi commentedCan u give me some tutorial for this.
Comment #3
redben CreditAttribution: redben commentedI have this problem too. It seems that context only works with primary and secondary links (have i missed something) AND the features menu if you have features installed.
Is this right ?
Comment #4
nwe_44 CreditAttribution: nwe_44 commentedI also have this issue, I tried changing the module weight to various options, including the heaviest weight in the site, and still no joy.
Any ideas?
Comment #5
ceardach CreditAttribution: ceardach commentedReassigning as a bug report because this is behaviour that should work.
Comment #6
ashiwebi CreditAttribution: ashiwebi commentedI created one menu under primary links and menu needs path then how we assign path for context?
Comment #7
redben CreditAttribution: redben commentedI think this is a theming/css class problem.
When i looked at the source the menu items i specified to be a active in the context actually have a class "active-trail" but not "active"
Comment #8
kyle_mathews CreditAttribution: kyle_mathews commentedI can confirm the same problem. I've crated a context that is triggered on a view and on a node type. The active menu *is* set when viewing the view but is not set when viewing just one node.
Changing component to code as this seems like a coding problem, not an interface problem.
Comment #9
kyle_mathews CreditAttribution: kyle_mathews commentedUpdate on my bug report. Why that the appropriate feature tab wasn't being set to active, it turned out, was I was printing the features menu in my theme. Context only sets links with the primary and secondary links menu to active. Once I set "primary-links" to use features, then links were set active appropriately.
Comment #10
schedal CreditAttribution: schedal commentedOn my end, I have a primary menu, I have selected the menu item I want to have the context active in, and it won't turn "ON" when I surf to the URL.
I don't know if this is an issue, but my primary links are all in the format:
page/%name
where page refers to a "panel" and %name is a name I give the menu which is an argument which is passed to the panel.
so I might have:
page/teachers
which calls up the panel named "page" and sends it the argument "teachers"
If I hardcode a path match to:
page/teachers it DOES work; but obviously this is less user friendly than using your mutli-select box.
Thanks for looking into this!!!
Best,
Comment #11
ceardach CreditAttribution: ceardach commentedAlright, I sat down to really try to solve this problem... and what it comes down to is that it really can't be fixed within the context module.
Context will only support adding the active-trail class to a menu link when a menu is rendered in the theme as either the primary or secondary links (see context_preprocess_page()). This is because, as far as I could tell after a few hours of investigation, there is no way to alter a menu link. At every level of the output of a menu link, there is no possible way to hook into it and add an additional class.
To compensate for this on my project, I'm adding a phptemplate_menu_item() function to my base theme's template.php file. It is a copy of theme_menu_item(), with an additional clause which will check to see if the link is part of the active paths for sites that use spaces or not. This should add the active-trail class in the majority of cases where the menu is rendered.
Since it appears as though there is no way to do this outside of the theme layer, I'm marking this ticket as won't fix. People can hopefully use the above example to solve this problem instead.
Comment #12
redben CreditAttribution: redben commentedAnother way of getting around this problem (if your use case allows it) is to have all your items as deep children of items on primary or secondary links then use menu_block to render the desired menu level on a different block. This is how i am doing it with my contexts
Comment #13
divbox CreditAttribution: divbox commentedI'm not using spaces, so I made following change and I now get active-trail on the LI tag.
I had to add CSS to apply active to LI element. primary_menu had the class "active" set on the A tag
Comment #14
abdulFarooqui CreditAttribution: abdulFarooqui commentedI created a block with PHP Code. Inside that block I called the functionmenu_set_active_item('node/xxx') ;
, where xxx is the node-id of the node linked to the menu-item I wanted to be active. I place this block on the page (in left side bar), it may not print anything, but it seems to do the job.Corrected: I noticed that calling the
menu_set_active_item
from the code of a block is not good. It also had some side-effects on active menu trail and bread crumbs, which I could not explain. So I abandoned this approach. In my specific case menutrails module worked.Comment #15
ceardach CreditAttribution: ceardach commentedJust as an update, this is the updated version of the code snippet above so it works with context 3 and spaces 3:
Comment #16
capellic@divbox, #13.
THANKS! This is exactly what I needed.
Comment #17
capellicI had a little problem with divbox's code in #13. I often use a node with as the top page in a section which is represented in the menu. This page often has a view in it via the Inset View module. This node has a title of "News" and a path (node/1) and an alias (news). When selecting "News" in context for the active menu, the paththat appears ins node/1 instead of news which causes problems because the code in #13 is trying to match on the alias. To overcome that, I've added the following code:
Here's the full function:
Comment #18
JThan CreditAttribution: JThan commentedI get a error that function context_active_values(); doesn't exist. I searched all files coming with Context Module and did not find that function. So this code can not be added.
Comment #19
owntheweb CreditAttribution: owntheweb commentedHere's my addition referencing the context 3 version that worked for me (with no spaces module used). Custom URL aliases were being used, so drupal_lookup_path() is added below. Let me know if it's discombobulated as I'm newish at this:
Comment #20
ryan_courtnage CreditAttribution: ryan_courtnage commented@Kyle_mathews (#9) Thanks for figuring this out and posting. I was seeing this problem with a custom menu I'd created. Setting it to be the "Source for the primary links" in the menu settings made Context/Active Menu work for me.
Comment #21
my-family CreditAttribution: my-family commentedThe same problem as #18 (context_active_values() is undefined, fatal error), please could anybody suggest what to do? Thanks
Comment #22
thomjjames CreditAttribution: thomjjames commentedHere's a little snippet I used to set the active menu trails using context with the nice_menus module:
In template.php:
Thought it might be useful to someone else.
Cheers
Tom
Comment #23
artwork CreditAttribution: artwork commentedThis not work for me (I'm using nice menu 6.x-1.3 and rename already changed THEMENAME_nice_menus_build to THEMENAME_nice_menu_build). Is this compatible with my version ?
Comment #24
artwork CreditAttribution: artwork commentedProblem solved
For nice menu version 6.x-1.3
changed
to
or
just use $active_paths = context_active_values('menu');
Don't sure if this will cause a problem, just my work around.
Comment #25
joep.hendrix CreditAttribution: joep.hendrix commented#22 works nice, thanks!
Comment #26
chrisfromredfin#24 didn't exactly work for me (the code is syntactically incorrect, to begin with). Here's the whole theme function that DID work for me, based on the example above and the theme code from nice_menus 1.3.
As usual, this belongs in your theme's template.php file (rename THEMENAME to your theme's name), and flush caches.
Comment #27
Macronomicus CreditAttribution: Macronomicus commentedYea this still doesnt work optimally even in the latest 3.x branch.
The better option is to use http://drupal.org/project/menutrails it works out of the box and is pretty awesome IMO.
Comment #28
dervishmoose CreditAttribution: dervishmoose commented@owntheweb #19 Your fix works, thanks!
ONE thing to note, drupal_lookup_path( can not look up the special string
<front>
. This means you can not use context to set a menu item active that uses<front>
as the path.Note: this does not solve for if the path is a URL address
A better solution should be improvised for the long term.
Here is the update that I am using to support special string
<front>
:Comment #29
EdinburghRob CreditAttribution: EdinburghRob commentedThanks this worked for me, but I had to add some code to handle my base path and also cases where the active menu was a path from a view and didn't have an alias. Maybe this will save somebody some time.
Comment #30
Alice Heaton CreditAttribution: Alice Heaton commentedHello,
If you don't need the class applied to the 'LI' element (eg. you have flat menus), then a more elegant solution (which applies the class to the 'A' element) is to use theme_menu_item_link instead. This way you don't need to have a regular expression on the path.
Implement theme_menu_item_link in your template.php as such :
This works great for me, but I haven't checked special cases such as <front>, etc. so you might need to improve it for these.
For people who use a Zen subtheme, note that Zen already overrides menu_item_link ; so you should copy the extra code back into this function (only a few lines).
Comment #31
noussh CreditAttribution: noussh commented#22 worked for me. Thanks
Comment #32
vegardjo CreditAttribution: vegardjo commentedThanks Anselm, didn't get the other examples to work, possibly because this was in an og / spaces group, and there might be some conflict with Purl, but #30 works like a charm in this setup too!
Comment #33
hedac CreditAttribution: hedac commentedI couldn't use any of the above codes... but I am using active-trail instead of active in the css and it works.
Comment #34
naero CreditAttribution: naero commentedThis still isn't fixed and none of the code above works for me either. Has there been any progress on this?
Comment #35
joeysantiago CreditAttribution: joeysantiago commentedUsing D7 i had to add this code to my basic template.php file:
It looks like working. Actually i would have preferred to override a theme function like the ones that appear in $variables array at ['#theme'] element... but couldn't find the right function name, probably?
Well, any help appreciated, thanks
Comment #36
grndlvl CreditAttribution: grndlvl commentedHere is #35 in a more generic form that works with drupal 7 out of the box.
Comment #37
grndlvl CreditAttribution: grndlvl commentedAlthough, I think this now can be fixed in the module with hook_preprocess_menu_link() in d7.
Unless there is something that is already there for that I will go ahead and create a patch for d7.
Comment #38
grndlvl CreditAttribution: grndlvl commentedwhoops forgot
Comment #39
grndlvl CreditAttribution: grndlvl commentedPatch to allow this to happen in d7.(basically same code from #36 inside of hook_preprocess_menu_link())
May write tests later.
Comment #40
grndlvl CreditAttribution: grndlvl commentedComment #41
grndlvl CreditAttribution: grndlvl commented/me being lazy... :) this is the right one now
Comment #42
rjbrown99 CreditAttribution: rjbrown99 commentedFWIW, I'm using #22 and it works well, except for the scenario where you have parent/child menus. In that case, the child menu has its active trail set and the class marked as active, but the parent is never set as part of the active trail.
Here's what I did to fix it. This is a short snippet that would go into #22. Instead of this section of the original code:
I changed it to this:
Comment #43
othermachines CreditAttribution: othermachines commented#22 (thomjjames) worked splendidly-- thanks!
Comment #44
benleivian CreditAttribution: benleivian commentedThanks! That did the trick.
Comment #45
bradjones1To help move this along: I required a patch to context in order to have menu path reactions affect menus in blocks. #41 appears to be the most succinct method of fixing this particular problem. The patch applied cleanly and works for me against 7.x-3.x-dev.
Patching this module for this narrow issue appears to be a more elegant solution than recommending work-arounds in theme templates.
I'm going to be bold and mark this RTBC - does a maintainer have a perspective on this?
Comment #46
rjbrown99 CreditAttribution: rjbrown99 commentedDoes #41 handle the parent/child menu issue described in #42? If not I'd say this is needs work.
Comment #47
bradjones1@rjbrown99: This ticket dates back to 2009 and was originally tagged to the 6.x version. I think the advent of hook_preprocess_HOOK in D7 may now 2 years later address the issue raised, even if it doesn't backport directly to 6.x versions of context.
#42 refers back to #22 which is a theme function suggestion, not a patch to context. Perhaps this thread should be honed in to D7 and if there's a backport or other solution needed for D6, that can be handled separately. Thoughts?
Comment #48
febbraro CreditAttribution: febbraro commentedCommitted the patch in #41. Could use more testing to know if it fixes #42, in my limited testing the path to the root of the menu was labeled as active. In any case this fixes part of the issue so I figured i would get it in (I'll be rolling a new release tomorrow I think) If it does not fix #42, then we can reopen this.
http://drupalcode.org/project/context.git/commit/289025b
Comment #49
arnemaine CreditAttribution: arnemaine commentedDoes the current 6x-3.0 version of Context have a patch to correct this issue?
Comment #50
grndlvl CreditAttribution: grndlvl commentedDue to the restrictions of Drupal < 7 the module cannot fix this issue. You would have to use one of the fixes above.
Comment #51
othermachines CreditAttribution: othermachines commentedI was hopeful, but in special circumstances it appears that the preprocessor (context_preprocess_menu_link) is reached before context has time to execute active contexts.
In my case, I've got a menu inside a panel pane. I'm using page_manager (ctools).
What's going on, as best as I can figure:
It appears that when
ctools_context_handler_render_handler('panels_panel_context_render')
is called from page_manager_node_view_page(), the page is being built on this line:$info = $function($handler, $contexts, $args);
---> Checking active contexts... what? Nothing?... which occurs before this line:
drupal_alter('ctools_render', ...)
---> Let's go set active contexts! (viacontext_ctools_render_alter
)Is this even fixable in this module or should I hassle someone else? I've been trying to come up with even a sloppy workaround but either I'm too tired or it's particularly sticky.
Running context 7.x-3.0-beta2 with ctools 7.x-1.0-rc1 with page_manager and panels 7.x-3.0-alpha3.
Comment #52
othermachines CreditAttribution: othermachines commentedFollowing up on #51:
Not sure if this is the most ideal workaround, but I came up with a 7.x patch that adds a preprocess_panels_pane() function to precede context_preprocess_menu_link(). Before I attach it, since the previous patch has been committed, I'm wondering if a new issue might be in order for this?
In context.module:
I'm not 100% sure this should only be triggered once (thus the static variable). Some insight on this would be awesome.
This can also be added to sites/all/themes/mytheme/template.php. I have both since I'm using a couple of non-standard conditions. Mine is below. (Notice the line
context_node_condition($context->data, 'view');
is absent; you'll need it if you're only changing template.php.)Cheers-
Comment #53
timcosgrove CreditAttribution: timcosgrove commented#41 assumes that the menu link is actually displaying when the context is active. If the context tries to activate a menu link that is nested and unexpanded this patch will not help.
Subscribing.
Comment #54
abdelatifs CreditAttribution: abdelatifs commentedHi guys,
Does anyone figured this by now without using any snippets ?
For some reasons I get white screen of death whenever I put any of those snippets in my template.php file.
Thanks for your help guys.
Comment #55
othermachines CreditAttribution: othermachines commented@abdekatifs: Update to context 7.x-3.0-beta2.
Comment #56
castawaybcn CreditAttribution: castawaybcn commentedI know this is an old issue, but I am getting the same wsods as @abdelatifs, did you find a solution to this?My bad, actually the solution in #30 worked like a charm for 6.x, thanks so much!
Comment #57
majorbenks CreditAttribution: majorbenks commentedAs far as I see: this problem exists also in 7.x beta 5. Or did I missed something?
Comment #58
tom92 CreditAttribution: tom92 commentedIt does not work in 7.x and none of the template work arounds are working at my site..
Comment #59
tom92 CreditAttribution: tom92 commentedComment #60
illmatix CreditAttribution: illmatix commentedWhich is the last patch that was suggested for Drupal 7.x?
Comment #61
Arnion CreditAttribution: Arnion commentedI hope this helps. You have to update the context after applying the patch.
Comment #62
mErilainen CreditAttribution: mErilainen commentedPatch seems to work, but also broke the active menu item condition which I have used in another context. All the menu items are still selected, but won't activate the context. Using a path condition works, but the site is multilingual, so it's easier to select the main menu items than write several lines of path selectors.
Comment #63
sagannotcarl CreditAttribution: sagannotcarl commentedSeems to me like this is a duplicate of #835090: Context Reaction: Set menu trail (unless I'm missing something about the differences).
Comment #64
anouDidn't read every comment (sorry) but I must say that for D6 context will not "active-trail" the menu item if it is configured via views menu option.not flagrant... I talked to fast... can't make it work...So I finally made it work with the help of #13 and the help of this post. Here's the final code for D6.28 and Context 6.x-3.1 :
(Everything goes in template.php)
I must say that I really got used to D7 and working in D6 is harder then before :-)
Comment #65
Karsa CreditAttribution: Karsa commentedI created a patch for this bug, please see #835090: Context Reaction: Set menu trail
Comment #66
malapeiro CreditAttribution: malapeiro commentedhi, dont know how to code, but i solve this issue with menu position module (https://drupal.org/project/menu_position) instead of context module. it works for me!