When context renders blocks, it does so by region. When it loops through the regions and renders associated blocks, it does so in no particular order, which defaults to whichever region happened to be listed first in the declaration of block reactions.

For instance, in the following example, the content region would be rendered first, followed by the header_top region.

$context->reactions = array(
  'block' => array(
    'blocks' => array(
      'system-main' => array(
        'module' => 'system',
        'delta' => 'main',
        'region' => 'content',
        'weight' => 0,
      ),
      'delta_blocks-logo' => array(
        'module' => 'delta_blocks',
        'delta' => 'logo',
        'region' => 'header_top',
        'weight' => -10,
      ),
    ),
  ),
);

While the following would render the header_top region first, followed by the content region.

$context->reactions = array(
  'block' => array(
    'blocks' => array(
      'delta_blocks-logo' => array(
        'module' => 'delta_blocks',
        'delta' => 'logo',
        'region' => 'header_top',
        'weight' => -10,
      ),
      'system-main' => array(
        'module' => 'system',
        'delta' => 'main',
        'region' => 'content',
        'weight' => 0,
      ),
    ),
  ),
);

This is especially a problem if you use the Delta module (to place Drupal messages in certain regions) and the Formblock module (to place, e.g. a User Registration form in different regions). In some combinations, the form will be processed after the messages are rendered, resulting in no error messages being displayed until the next page load.

The solution would involve sorting the regions before rendering the region's blocks in context_reaction_block::block_list() in a way that matched system_region_list().

Comments

eric.chenchao’s picture

StatusFileSize
new910 bytes

I have also got a problem caused by region render order.

My scenario is I have created two contexts.

The first one is for category A and I have put solr listing form (search_api, search_api_solr & views) in the content region and put facet block (facetapi) in the first_sidebar region. It works well.

Then I have created the second context, add a newsletter subscription form across category A, B and C in the first_sidebar region.

Then When I check the category A page, the facet block just gone.

It took me a while to debug and finally found that the region render order just changed when the second context has been enabled, as facet block needs solr listing form in the content region to run first to make sure search server is active in this page.

I have tried to tweak context execute order by using a sandbox module context_weight, but no success. Maybe because I use feature module to export part of contexts.

So I have write a patch to make context region render order as same as core and it works.

eric.chenchao’s picture

Status: Active » Needs review
iamEAP’s picture

Status: Needs review » Reviewed & tested by the community

I've applied the patch in #1 and can confirm it resolves the issue.

  • colan committed 536de40 on 7.x-3.x authored by eric.chenchao
    Issue #1922840 by eric.chenchao | iamEAP: Render regions in the same...
colan’s picture

Version: 7.x-3.x-dev » 7.x-3.3
Status: Reviewed & tested by the community » Fixed

Thanks!

eric.chenchao’s picture

Great, thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.