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.
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;
+ }
}
}
}
Comment | File | Size | Author |
---|---|---|---|
#1 | context-empty-regions-1100610-1.patch | 760 bytes | setvik |
Comments
Comment #1
setvik CreditAttribution: setvik commentedComment #2
setvik CreditAttribution: setvik commentedComment #3
jwolf CreditAttribution: jwolf commentedHere is an example of a theme's implementation of html preprocess function which is using isset that causes this issue:
Comment #4
setvik CreditAttribution: setvik commentedComment #5
setvik CreditAttribution: setvik commentedComment #6
febbraro CreditAttribution: febbraro commentedThanks.
http://drupalcode.org/project/context.git/commit/a1771c0