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?

Comments

tahiticlic’s picture

Title: Conflict with Zn subthemes? » Conflict with Zen subthemes?

Moreover, in regions list, I've both the Garland and the zen subtheme regions.

mrfelton’s picture

I can confirm this. Blocks appear when using garland, but not zen.

mrfelton’s picture

the problem lies somewhere in the zen_blocks() function.

jmiccolis’s picture

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

mrfelton’s picture

I made the zen people aware of this issue:
http://drupal.org/node/634552

tahiticlic’s picture

Confirmed : 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 :

<?php
function YOURTHEMENAME_blocks($region, $show_blocks = NULL) {
	
	if (module_exists("context")){
	  
	  // Since Drupal 6 doesn't pass $show_blocks to theme_blocks, we manually call
	  // theme('blocks', NULL, $show_blocks) so that this function can remember the
	  // value on later calls.
	  static $render_sidebars = TRUE;
	  if (!is_null($show_blocks)) {
	    $render_sidebars = $show_blocks;
	  }
	  
		// Bail if this region is disabled.
	  $disabled_regions = context_active_values('theme_regiontoggle');
	  if (!empty($disabled_regions) && in_array($region, $disabled_regions)) {
	    return '';
	  }

	  // If zen_blocks was called with a NULL region, its likely we were just
	  // setting the $render_sidebars static variable.
	  if ($region) {
	    $output = '';
	
	    // If $renders_sidebars is FALSE, don't render any region whose name begins
	    // with "sidebar_".
	    if (($render_sidebars || (strpos($region, 'sidebar_') !== 0)) && ($list = context_block_list($region))) {
	      foreach ($list as $key => $block) {
	        // $key == module_delta
	        $output .= theme('block', $block);
	      }
	    }
	
	    // Add any content assigned to this region through drupal_set_content() calls.
	    $output .= drupal_get_content($region);
	
	    $elements['#children'] = $output;
	    $elements['#region'] = $region;
	
	    return $output ? theme('region', $elements) : '';
	  }
	  
	}
	else return zen_blocks($region, $show_blocks);
}
?>

This does a mix between standard zen hook_blocks and context hook_blocks.

mrfelton’s picture

For the record, this issue only exists with zen2.

johnalbin’s picture

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

mpaler’s picture

The code above cause all blocks to disappear on my site. I'll need to dig in some more :(

Herman Hiddema’s picture

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

yhahn’s picture

Title: Conflict with Zen subthemes? » CONFIRMED: Conflict with Zen 2.x

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

mpaler’s picture

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

mpaler’s picture

@cfab where are you finding function zen_blocks?

tahiticlic’s picture

In Zen's template.php file.

alexkb’s picture

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

gmclelland’s picture

Mike_Waters’s picture

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

summit’s picture

Subscribing, greetings, Martijn

marshallbu’s picture

Version: 6.x-2.0-beta7 » 6.x-3.0-beta4

Hey 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 :

/* testing for compatibility with context */
function YOURTHEME_blocks($region, $show_blocks = NULL) {

    if (module_exists("context")){
      
      // Since Drupal 6 doesn't pass $show_blocks to theme_blocks, we manually call
      // theme('blocks', NULL, $show_blocks) so that this function can remember the
      // value on later calls.
      static $render_sidebars = TRUE;
      if (!is_null($show_blocks)) {
        $render_sidebars = $show_blocks;
      }
      
      // Bail if this region is disabled.
      //$disabled_regions = context_active_values('theme_regiontoggle');
      //if (!empty($disabled_regions) && in_array($region, $disabled_regions)) {
        //return '';
      //}

      // If zen_blocks was called with a NULL region, its likely we were just
      // setting the $render_sidebars static variable.
      if ($region) {
        $output = '';

		$plugin = context_get_plugin('reaction', 'block');
    
        // Add any content assigned to this region through drupal_set_content() calls.
        $output .= $plugin->execute($region);
    
        $elements['#children'] = $output;
        $elements['#region'] = $region;
    
        return $output ? theme('region', $elements) : '';
      }
    }
    else {
		return zen_blocks($region, $show_blocks);
	}
}

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!

sunshinee’s picture

subscribe

mrfelton’s picture

@marshallbu - seems to be working for me. good job :)

marshallbu’s picture

great, 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.

Anonymous’s picture

Subscribe.

jalneal’s picture

Subscribe

lee20’s picture

Subscribe

bryan_t’s picture

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

gausarts’s picture

Subscribing. Thanks

brentratliff’s picture

subscribing

vosechu’s picture

subscribing

tahiticlic’s picture

Code adapted by marshallbu works well for context 3b4 with zen 2.x

bonobo’s picture

Just 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

dvessel’s picture

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

dvessel’s picture

Hrm, scrap that. Just noticed context_blocks() needs to catch the whole output so it's not as simple as adding a preprocess function.

bonobo’s picture

FYI: this approach worked for us with Hexagon.

dvessel’s picture

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

traviscarden’s picture

Zen has a patch to resolve the issue on its side at #634552: Conflict with context module.

jhedstrom’s picture

Subscribing.

jejk’s picture

Subscribing

my-family’s picture

Version: 6.x-3.0-beta4 » 6.x-3.0-beta5

Subscribing.
#19 works with Zen 2.x-dev and Context 6.x-3.0-beta5, thank you

danny_joris’s picture

Subscribing

batje’s picture

To 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

          // Add any content assigned to this region through drupal_set_content() calls.
        if (is_object($plugin)) {
          $output .= $plugin->execute($region);
        }
halcyonCorsair’s picture

Subscribing.

yhahn’s picture

Status: Active » Closed (duplicate)
johnalbin’s picture

Title: CONFIRMED: Conflict with Zen 2.x » Conflict with themes implementing theme_blocks()
Version: 6.x-3.0-beta5 » 6.x-3.x-dev
Category: support » bug
Status: Closed (duplicate) » Needs review
StatusFileSize
new2.52 KB

I'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.

johnalbin’s picture

StatusFileSize
new2.52 KB

Tim Plunkett tested the patch and noticed a typo in the patch. Here's an updated patch.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

This is an elegant solution to a very common issue. No more will Context be a burden on themers!

OnkelTem’s picture

Genius! Thank you, John!

jethro’s picture

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

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work

Someone 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!

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

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

gstout’s picture

subscribe.

gstout’s picture

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

EndyBoooj’s picture

Subscribe

tahiticlic’s picture

Following the first method, there's an even simpler code today :

<?php
/* testing for compatibility with context */
function YOURTHEME_blocks($region, $show_blocks = NULL) {
  if (module_exists("context")){
      if ($plugin = context_get_plugin('reaction', 'block')) {
      return $plugin->execute($region);
    }
  }else{
     return zen_blocks($region, $show_blocks);
  }
}
?>

I haven't tested yet with Zen, but that's the same problem with all Rocketthemes themes and that works right this way.

tim.plunkett’s picture

Yes, 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.

mr.andrey’s picture

subscribing

tahiticlic’s picture

Yes, 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.

I know, I've opened this thread in this purpose. But solutions are still solutions until the good correction occurs in Context.

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
lookatyeti’s picture

The solution from #54 does not work with Zen 2.x, use the code from comment #19

lord_of_freaks’s picture

Subscribing

daniel-san’s picture

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

stevenator’s picture

subscribing

franz’s picture

@daniel-san, it IS a bug on Context, but themes can workaround it (like the patch on Zen).

sean_a’s picture

#19 works for the default zen regions but doesn't work for me on additional regions added in a subtheme

sean_a’s picture

update: #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

kirkcaraway’s picture

I'm having the same problem with my Rocketthemes theme, and I tried the fix in #54, but came up with this error:

Fatal error: Cannot redeclare nexus_blocks() (previously declared in ...

Is there something I missed, such as where to put this code?

Thanks.

franz’s picture

Yes, you redeclared a function, which means there is a nexus_blocks() function already. Search for it and use it.

kevin p davison’s picture

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

henk’s picture

"#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!

bkosborne’s picture

subscribe

samireez’s picture

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

vasike’s picture

subscribe

kip stanning’s picture

thx everybody, worked great for me!

johnalbin’s picture

Priority: Normal » Major

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

johnalbin’s picture

Issue summary: View changes

Added issue summary.

johnalbin’s picture

Status: Needs work » Needs review
StatusFileSize
new2.94 KB

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

johnalbin’s picture

Issue summary: View changes

Clarified why Zen 6.x-2.0 was used to test the patch.

thedavidmeister’s picture

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

thedavidmeister’s picture

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

shawngo’s picture

#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].

wizonesolutions’s picture

Status: Needs review » Reviewed & tested by the community

#75 worked for me. Block wasn't showing up, applied patch, block showed up. RTBC-ing since I'm basically the third reviewer.

mynameiscorey’s picture

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

soulfroys’s picture

#75 still works (last stable). Make #916194: Block regions missing from admin/build/block as a duplicated of this issue.

soulfroys’s picture

Issue summary: View changes

Added note about new patch in #75.

kristen pol’s picture

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

Thanks to everyone for the work on this issue. Closing as outdated as this is for Drupal 6.