Problem/Motivation
If a context is defined where blocks should appear, the blocks may not show up as desired depending on which theme is used on the website. If a theme implements an override of theme_blocks(), then the Context module won't work with that theme. Since all theme_ functions are designed to be overridden by themes, the problem needs to be fixed in the Context module.
Proposed resolution
Remove context's theme_blocks() override. And, in context_page_alter() (context's preprocess_page function), it can go through all the regions and set the blocks with drupal_set_content().
Remaining tasks
Using patch in comment #45, blocks added through the normal blocks admin page are added to each region twice, as duplicates. If the variable context_reaction_block_disable_core is not TRUE, context_reaction_block's ->execute() will include core blocks, printing them twice.
Patch in #75 may fix this bug, but it needs testing.
Note: the patches need testing with Zen 6.x-2.0, an old version of Zen, since 6.x-2.1 and later implement a work-around for this Context bug.
Original report by tahiticlic
Hi,
I've an issue with a zen subtheme and Context : I've defined a context where blocks should appear. With a garland subtheme, no problem. With a zen subtheme, the blocks don't show... I've limited the theme to this only subtheme
Any idea of what I'm doing wrong?
| Comment | File | Size | Author |
|---|---|---|---|
| #75 | 633778-75-conflict-with-theme_blocks.patch | 2.94 KB | johnalbin |
| #45 | 633778-45-conflict-with-theme_blocks.patch | 2.52 KB | johnalbin |
| #44 | 633778-conflic-with-theme_blocks.patch | 2.52 KB | johnalbin |
Comments
Comment #1
tahiticlic commentedMoreover, in regions list, I've both the Garland and the zen subtheme regions.
Comment #2
mrfelton commentedI can confirm this. Blocks appear when using garland, but not zen.
Comment #3
mrfelton commentedthe problem lies somewhere in the zen_blocks() function.
Comment #4
jmiccolis commented@mrfelton chances are that the fact that the zen_blocks() function exists *is* the problem. Context also implements theme_blocks(), which it uses to populate the block regions.
Comment #5
mrfelton commentedI made the zen people aware of this issue:
http://drupal.org/node/634552
Comment #6
tahiticlic commentedConfirmed : without the function blocks do show, but the display is totally messed (because of sidebars I think).
Well, at least the problem's origin is well known.
[EDIT : A SOLUTION]
Here's a solution that works for my own case at least :
add this function to your zen subtheme template.php file :
This does a mix between standard zen hook_blocks and context hook_blocks.
Comment #7
mrfelton commentedFor the record, this issue only exists with zen2.
Comment #8
johnalbinZen 6.x-2.x just implements theme_blocks as a way to add a region.tpl.php template like D7 has.
Subscribing. I'll have to spend some time on this to think of a good solution before Zen 6.x-2.0 is released.
Comment #9
mpaler commentedThe code above cause all blocks to disappear on my site. I'll need to dig in some more :(
Comment #10
Herman Hiddema commentedIf I am not mistaken, this bug has the exact same cause as #457512: i18n blocks creates conflicts with themes and modules that override the theme_blocks function
The problem is that both Context and Zen2 override the theme_blocks function. The i18n module does this as well, which caused conflicts with both Context and Zen2. The i18n project have a working patch where they use hook_preprocess_block instead, but I don't know how feasible that is for Context.
Comment #11
yhahn commentedThanks everyone for tracking this down. There isn't really a good entry point other than
theme_blocks()to alter the core block visibility behavior, and so that is where context does its thing.I'll keep thinking about clean ways to resolve this issue as well.
Comment #12
mpaler commentedThanks for the update. I would love to bump this up to critical. In may case it's stopping me from using Context & Features because I'm married to the zen theme at this point. Unfortunately, this issue falls in that gray area b/w a bug and modules simply not playing nice together. Bummer.
Comment #13
mpaler commented@cfab where are you finding function zen_blocks?
Comment #14
tahiticlic commentedIn Zen's template.php file.
Comment #15
alexkb commentedSo glad someone found this issue before now as it was really causing us some grief! Thanks cfab!
It should be noted that the cfab's solution (#6) won't work with version 3.x of context. I don't have time to code up an alternative, but will try in a few days. In the meantime, I just commented out the zen_blocks() function to solve the problem.
Thanks.
Comment #16
gmclelland commentedMaybe this helps this issue?
http://www.alldrupalthemes.com/drupal-blog/want-your-theme-be-compatible...
Comment #17
Mike_Waters commentedRemoving Zen's hook_block() causes several of Zen's regions to render un-themed.
Can anyone recommend a base theme that supports Context natively, that will also allow one to theme without worrying over browser inconsistencies and the like? (Tao, or Rubik etc.)
(Context 6.x-3.0-beta3)
Comment #18
summit commentedSubscribing, greetings, Martijn
Comment #19
marshallbu commentedHey guys,
I got this working with Zen 2.x and Context 6.x-3.0-beta4, after sitting down and looking how Context 3.0 does its thing. So far, it works perfectly, and doesn't leave out Zen's block themeing as mentioned above.
Going along with @cfab's solution, I was able to come up with the following zen subtheme function for your template.php file :
I am still working on figuring out how to bail if the region is disabled, as I haven't found a function yet that compares to "context_active_values" in Context 3.0, let me know what you guys think!
Comment #20
sunshinee commentedsubscribe
Comment #21
mrfelton commented@marshallbu - seems to be working for me. good job :)
Comment #22
marshallbu commentedgreat, good to hear. I still haven't found a replacement block of code for the active regions area, but I haven't noticed any performance draw backs just yet.
Comment #23
Anonymous (not verified) commentedSubscribe.
Comment #24
jalneal commentedSubscribe
Comment #25
lee20 commentedSubscribe
Comment #26
bryan_t commentedI tried the code that marshallbu posted, but it didn't work for me. I'm using zen 6.x-2.x and context 3.x beta-4.
Comment #27
gausarts commentedSubscribing. Thanks
Comment #28
brentratliff commentedsubscribing
Comment #29
vosechu commentedsubscribing
Comment #30
tahiticlic commentedCode adapted by marshallbu works well for context 3b4 with zen 2.x
Comment #31
bonobo commentedJust an FYI: we are seeing a similar issue with blocks not appearing using Hexagon/Canvas.
I put an issue in the Hex queue pointing here: #811152: Possible conflict with Context
Comment #32
dvessel commented@yhahn, could Context account for themes overriding theme_blocks converted into a template? The theme Bonobo mentions doesn't use a theme function for the override.
Just provide a preprocess function for blocks then the theme won't have to hard code any fixes since it'll be included automatically.
Comment #33
dvessel commentedHrm, scrap that. Just noticed context_blocks() needs to catch the whole output so it's not as simple as adding a preprocess function.
Comment #34
bonobo commentedFYI: this approach worked for us with Hexagon.
Comment #35
dvessel commentedThat approach would only work for Hexagon since it supports mini plug-in's.
This is just an idea and it might be a really bad one but if Context could create two fake blocks and position them first and last for each region, it could create the wrapper needed for context. That way, there would be no need for overriding any theme function.
That would also mean a good amount of rewriting the context plug-in for handling blocks. Might not be worth the trouble.
Comment #36
traviscarden commentedZen has a patch to resolve the issue on its side at #634552: Conflict with context module.
Comment #37
jhedstromSubscribing.
Comment #38
jejk commentedSubscribing
Comment #39
my-family commentedSubscribing.
#19 works with Zen 2.x-dev and Context 6.x-3.0-beta5, thank you
Comment #40
danny_joris commentedSubscribing
Comment #41
batje commentedTo prevent Contexts that do not use the block reaction to throw a
Call to a member function execute() on a non-object in...
error in the #19 code
here is the 2 lines to fix
Comment #42
halcyonCorsair commentedSubscribing.
Comment #43
yhahn commented#634552: Conflict with context module
Comment #44
johnalbinI'm actually working on a patch for Zen 2 that will fix the incompatibility with Context 6.x-2.0 and Context 6.x-3.0.
However, I thought of a way that context may be able to avoid the problem of it not wanting to override theme_blocks() when a theme also overrides it.
In context_page_alter() (context's preprocess_page function), it can go through all the regions and set the blocks with drupal_set_content(). Here's a totally untested patch.
Comment #45
johnalbinTim Plunkett tested the patch and noticed a typo in the patch. Here's an updated patch.
Comment #46
tim.plunkettThis is an elegant solution to a very common issue. No more will Context be a burden on themers!
Comment #47
OnkelTem commentedGenius! Thank you, John!
Comment #48
jethro commentedUsing patch in comment #45 with a zen sub-theme and Context-3.0, blocks added through the normal blocks admin page are added to each region twice, as duplicates.
Comment #49
tim.plunkettSomeone else reported this in IRC. I didn't see that when I tested it, but I'm going to get to the bottom of this!
Comment #50
tim.plunkettIf the variable context_reaction_block_disable_core is not TRUE, context_reaction_block's ->execute() will include core blocks, printing them twice.
Not sure what to do about that, but I'll get back to it tomorrow.
Comment #51
gstout commentedsubscribe.
Comment #52
gstout commentedThank you marshallbu for #19. This may not "fix" the problem but it got me back on track with two theme projects I has almost finished. Thanks so much for your time that you put into making this work. It is appreciated marshallbu.
Comment #53
EndyBoooj commentedSubscribe
Comment #54
tahiticlic commentedFollowing the first method, there's an even simpler code today :
I haven't tested yet with Zen, but that's the same problem with all Rocketthemes themes and that works right this way.
Comment #55
tim.plunkettYes, Zen now implements a similar solution.
However, the goal of this thread is for Context to now longer require themers to provide Context-specific workarounds. Trust me, it's been a huge barrier for entry among new themers when convincing them to use Context.
Comment #56
mr.andrey commentedsubscribing
Comment #57
tahiticlic commentedI know, I've opened this thread in this purpose. But solutions are still solutions until the good correction occurs in Context.
Comment #58
tim.plunkettComment #59
lookatyeti commentedThe solution from #54 does not work with Zen 2.x, use the code from comment #19
Comment #60
lord_of_freaks commentedSubscribing
Comment #61
daniel-san commentedWas banging my head against the desk trying to understand Context for the first time. Just used the solution in #19 on Zen 6.x-2.0 using Context 6.x-3.0 and it worked great. Good to know that it was the theme and not my misunderstanding of the module.
Comment #62
stevenator commentedsubscribing
Comment #63
franz@daniel-san, it IS a bug on Context, but themes can workaround it (like the patch on Zen).
Comment #64
sean_a commented#19 works for the default zen regions but doesn't work for me on additional regions added in a subtheme
Comment #65
sean_a commentedupdate: #64 nevermind, I was missing something obvious
I hadn't declared the regions in the context layout section on the .info file layouts[CONTEXTLAYOUTNAME][regions][] = REGIONNAME
Comment #66
kirkcaraway commentedI'm having the same problem with my Rocketthemes theme, and I tried the fix in #54, but came up with this error:
Is there something I missed, such as where to put this code?
Thanks.
Comment #67
franzYes, you redeclared a function, which means there is a nexus_blocks() function already. Search for it and use it.
Comment #68
kevin p davison commentedI haven't used Zen in a while, and was banging my head on the desk until marshallbu's help on #19. Thanks! Luckily I don't need to add any new regions... yet.
Comment #69
henk commented"#19 works for the default zen regions but doesn't work for me on additional regions added in a subtheme"
#19 for me works also on added new region (with Zen 6.x-2.0 and Context 6.x-3.0). I generate subthemes in zenophile and add new sidbar, for now all context blok is visible.
Thanks for solution to my problem!
Comment #70
bkosbornesubscribe
Comment #71
samireez commentedJust to confirm that #19 works with Drupal 6.20, Context 6.x-3.0, Zen 6.x-2.0 and a subtheme of Zen. Thank you, marshallbu and tahiticlic!
#54 version looked nicer in terms of amount of code, but did not work as expected. There were signs of Context actually appearing in regions.
In regards to #69's issue - #19 also works with subtheme's additionally defined regions for me.
I'm wondering if it would be possible to have a small note added to the project's page (or readme or elsewhere) to warn users of this issue with Zen and other similar themes until the issue is resolved?
Comment #72
vasikesubscribe
Comment #73
kip stanning commentedthx everybody, worked great for me!
Comment #74
johnalbinZen 6.x-2.1 has been out for a while and has a work-around for this Context bug. You don't need to patch Zen to have it work with Context. And the problem doesn't exist in Zen 7.x-3.x since it no longer needs to implement theme_blocks().
This issue is borderline critical, but I'll leave it at major since only one feature is completely broken.
Comment #74.0
johnalbinAdded issue summary.
Comment #75
johnalbinThis should fix the bug described by Jethro and Tim in #48/50 above. Patch is untested.
Looks like Context 7.x-3.x won't need this since it's no longer overriding theme_blocks().
Comment #75.0
johnalbinClarified why Zen 6.x-2.0 was used to test the patch.
Comment #76
thedavidmeister commented#75 is working fine for me, but i'm not totally across the bug that it was created to address. Not seeing any duplicates, but I didn't try the older patch either.
Comment #77
thedavidmeister commentedone of my views blocks went missing until I cleared the site cache today, could be related to this patch but I'm not sure.. will wait to see what other people say.
Comment #78
shawngo commented#75 worked for me as well.
I applied the patch incorrectly the first time which missed the update for plugins/context_reaction_block.inc. I was experiencing the duplicate block issue until I reverted and applied the patch correctly with
git apply -v [patch-name.patch].Comment #79
wizonesolutions#75 worked for me. Block wasn't showing up, applied patch, block showed up. RTBC-ing since I'm basically the third reviewer.
Comment #80
mynameiscorey commented#75 worked for for me with no issues. My sitewide context for blocks in a custom region is finally working immediately after applying the patch.
Comment #81
soulfroys#75 still works (last stable). Make #916194: Block regions missing from admin/build/block as a duplicated of this issue.
Comment #81.0
soulfroysAdded note about new patch in #75.
Comment #82
kristen polThanks to everyone for the work on this issue. Closing as outdated as this is for Drupal 6.