The Context sets empty regions to empty arrays in context_page_build. This can confuse themes/modules that use isset to test for empty regions in hook_preprocess_html's $vars for example.

The patch below adjusts the code to only set the region if context has blocks to place in the region. (I'll attach the below as a patch file in the first comment).

     // Load all region content assigned via blocks.
     foreach (array_keys($all_regions) as $region) {
       if ($this->is_enabled_region($region)) {
-        $page[$region] = isset($page[$region]) ? array_merge($page[$region], $this->block_get_blocks_by_region($region)) : $this->block_get_blocks_by_region($region);
+        if ($blocks = $this->block_get_blocks_by_region($region)) {
+          $page[$region] = isset($page[$region]) ? array_merge($page[$region], $blocks) : $blocks;
+        }
       }
     }
   }
CommentFileSizeAuthor
#1 context-empty-regions-1100610-1.patch760 bytessetvik
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

setvik’s picture

setvik’s picture

Status: Active » Needs review
jwolf’s picture

Here is an example of a theme's implementation of html preprocess function which is using isset that causes this issue:

  <?php

    function mytheme_preprocess_html(&$vars) {
      $vars['classes_array'][] = 'layout-'. (isset($vars['page']['sidebar_first']) ? 'first-main' : 'main') . (isset($vars['page']['sidebar_second']) ? '-second' : '');
    }

  ?>
setvik’s picture

Version: 7.x-3.0-beta1 » 7.x-3.x-dev
setvik’s picture

Priority: Normal » Major
febbraro’s picture

Status: Needs review » Closed (fixed)