This a Drupal 7 version of the patch listed in #1000360: Contextual disabling of core block rendering. It is a great feature and it would be nice to see it in the release version.

It provides a select box in the Reactions -> Blocks area to enable/disable core blocks. When set to disabled, any regions configured within the current context are only populated with blocks from the context.

This is my first patch, so it's probably not perfect and I'm not certain I handled things the best way. Tips or suggestions are welcome.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

guillaumev’s picture

Status: Active » Reviewed & tested by the community

This is working well and would love to see this integrated in context as well. One small improvement to be done though: I was hoping to use this in order to have the main content block disabled in the content region, however for this specific block (the main content block) for some reason it doesn't work. With all other blocks it works just fine...

hefox’s picture

Status: Reviewed & tested by the community » Needs review

More than one review is likely be warrented

ns_j’s picture

Seems to have solved the problem for me. Thanks!

hefox’s picture

Status: Needs review » Needs work
+++ b/plugins/context_reaction_block.inc
@@ -28,6 +28,19 @@ class context_reaction_block extends context_reaction {
+    ¶

White space

+++ b/plugins/context_reaction_block.inc
@@ -28,6 +28,19 @@ class context_reaction_block extends context_reaction {
+      '#default_value' => isset($options['disable_core_blocks']) ? $options['disable_core_blocks'] : 0,

This could likely be simplified to !empty($options['disable_core_blocks']).

Not sure if a select vs a simple checkbox is better here.

+++ b/plugins/context_reaction_block.inc
@@ -216,11 +232,23 @@ class context_reaction_block extends context_reaction {
+      if (!empty($options['disable_core_blocks'])) {

The regions the blocks are in are the regions disabled for that context? Seems a bit confusing; would it be possible/better to have a reaction that disabled core blocks in regions (with region selection)?

+++ b/plugins/context_reaction_block.inc
@@ -216,11 +232,23 @@ class context_reaction_block extends context_reaction {
+          $page[$region] = isset($page[$region]) ? (isset($core_disabled_regions[$region]) ? $blocks : array_merge($page[$region], $blocks)) : $blocks;

Two level deep ternary, but only two possible outcomes ($blocks or array_merge); likely can be switched over to one level, which would be easier to read.
isset($page[$region]) && !isset($core_disabled..) ? arraY_merge : $blocks

jrabeemer’s picture

This patch is much needed. Disabling block rendering while not disabling Blocks UI (because other modules place their UI inside Blocks UI) is very useful and makes Context a complete blocks replacement.

In my use case, I want to remove messages block and "Main page content" from rendering, no default blocks rendered and totally rely on Context for all block placement.

+1 to #4 suggestions for code clean up.

Also provide a "Main page content" must be present and in a visible region warning. Otherwise you could end up with an empty admin page with no way to fix it unless you use Drush to re-enable Block module.

Orkut Murat Yılmaz’s picture

IMHO, this patch must be included in next update.

Ömer Atakoğlu’s picture

Please add this patch to the next update.

PCateNumbersUSA’s picture

Is there an updated patch for beta4? Any word on whether this functionality will be included in the next release?

mzwyssig’s picture

I would be very interested for this feature to be released in the next version as well.

jessia’s picture

Did anything ever happen with this patch? I've been looking for something like this!

ianthomas_uk’s picture

With the patch as it stands Drupal will still go to all the work of rendering the block, even though it's not displayed. Depending on the block in question that could add significant work/delay to the page load. Can we not stop these blocks from being rendered in the first place?