Could be related to #966768: Notice: Undefined property: stdClass::$content in _block_get_renderable_array when saving a configured context, but since that's an old issue, here's a new one.

Per https://drupal.org/node/966768#comment-6899716, the issue appears when using

if ($plugin = context_get_plugin('reaction', 'block')) {
  $variables['sidebar_content'] = $plugin->block_get_blocks_by_region($region);
}

Adding drupal_static_reset('context_reaction_block_list'); solves the issue but it is a performance killer, depending on where you called it.

Comments

rrrob’s picture

Issue summary: View changes

Not a fix, but a workaround. I use this in my template.php as a helper function.

function _mytheme_blocks_by_region($region) {
  $context_blocks = array();
  $block_blocks = array();
  // Blocks that are assigned to the region using Context
  if (function_exists('context_get_plugin') && $context = context_get_plugin('reaction', 'block')) {
    if ($context_block_list = $context->block_list($region)) {
      // Workaround the $context->block_get_blocks_by_region() issue.
      // See https://drupal.org/node/966768
      $fixed_context_block_list = _block_render_blocks($context_block_list);
      $context_blocks = _block_get_renderable_array($fixed_context_block_list);
    }
  }
  // Blocks that are assigned to the region using the blocks interface
  if ($blocks = block_get_blocks_by_region('content_bottom')) {
    $block_blocks = $blocks;
  }
  return array_merge($context_blocks, $block_blocks);
}
bjorsen’s picture

Thanks rrrob, that seems to work nicely for me too with a small change to the last conditional (using the $region var instead of hard-coded region name).

function _mytheme_blocks_by_region($region) {
  $context_blocks = array();
  $block_blocks = array();
  // Blocks that are assigned to the region using Context
  if (function_exists('context_get_plugin') && $context = context_get_plugin('reaction', 'block')) {
    if ($context_block_list = $context->block_list($region)) {
      // Workaround the $context->block_get_blocks_by_region() issue.
      // See https://drupal.org/node/966768
      $fixed_context_block_list = _block_render_blocks($context_block_list);
      $context_blocks = _block_get_renderable_array($fixed_context_block_list);
    }
  }
  // Blocks that are assigned to the region using the blocks interface
  if ($blocks = block_get_blocks_by_region($region)) {
    $block_blocks = $blocks;
  }
  return array_merge($context_blocks, $block_blocks);
}
kumkum29’s picture

Hello,

i get the same notices on my site when I defines a region in a _preprocess_views_view(&$variables) function.
I want to insert a custom region in a views-view...template.
I use this code:

function mytheme_preprocess_views_view(&$variables) {
	// Add the "right" region inside view
	if ($plugin = context_get_plugin('reaction', 'block')) {
		$variables['region_right'] = $plugin->block_get_blocks_by_region('right');
	}
}

I have tested your funcion without success.
Should I change anything in my function for resolve this?

Thanks for your help.

kumkum29’s picture

Hello bjorsen or rrrob,

where do you placed this function? I copied this code in my template.php, renamed 'my theme' with the name of my theme and cleared the cache without success.
Do I must copy this function before or after to my code:

if ($plugin = context_get_plugin('reaction', 'block')) {
		$variables['region_right'] = $plugin->block_get_blocks_by_region('right'); ...

Thanks for your help.

bjorsen’s picture

Hi kumkum29,

apologies for the slow response. I hadn't noticed any activity on this issue.

For future reference: you define the custom function in your template.php file and then call that custom function instead of the default to assign the content to the region. See example below based on your code.

$variables['region_right'] = _mytheme_blocks_by_region('right');