public function theme_area($theme, $area, $context = null, $scope = null)
{
// This array would normally come from the database via:
$scopes = $this->get_scopes($area);
$active_scope = 0;
foreach ($scopes as $scope_id => $scope_object) {
if (is_null($scope) && $this->check_scope_criteria($scope_object->criteria) || $scope == $scope_object->name) {
$scope_block_count = DB::get_value('SELECT count( *) FROM {blocks_areas} ba WHERE ba.scope_id = ?', array($scope_object->id));
if ($scope_block_count > 0) {
$active_scope = $scope_object->id;
}
break;
}
}
$area_blocks = $this->get_blocks($area, $active_scope, $theme);
$this->area = $area;
if (isset($context)) {
$this->context[] = $context;
}
// This is the block wrapper fallback template list
$fallback = array($area . '.blockwrapper', 'blockwrapper', 'content');
if (!is_null($context)) {
array_unshift($fallback, $context . '.blockwrapper');
array_unshift($fallback, $context . '.' . $area . '.blockwrapper');
}
$output = '';
$i = 0;
foreach ($area_blocks as $block_instance_id => $block) {
// Temporarily set some values into the block
$block->_area = $area;
$block->_instance_id = $block_instance_id;
$block->_area_index = $i++;
$block->_fallback = $fallback;
$hook = 'block_content_' . $block->type;
Plugins::act($hook, $block, $this);
Plugins::act('block_content', $block, $this);
$block->_content = implode('', $this->content_return($block, $context));
if (trim($block->_content) == '') {
unset($area_blocks[$block_instance_id]);
}
}
// Potentially render each block inside of a wrapper.
reset($area_blocks);
$firstkey = key($area_blocks);
end($area_blocks);
$lastkey = key($area_blocks);
foreach ($area_blocks as $block_instance_id => $block) {
$block->_first = $block_instance_id == $firstkey;
$block->_last = $block_instance_id == $lastkey;
// Set up the theme for the wrapper
$this->block = $block;
$this->content = $block->_content;
// This pattern renders the block inside the wrapper template only if a matching template exists
$newoutput = $this->display_fallback($fallback, 'fetch');
if ($newoutput === false) {
$output .= $block->_content;
} else {
$output .= $newoutput;
}
// Remove temporary values from the block so they're not saved to the database
unset($block->_area);
unset($block->_instance_id);
unset($block->_area_index);
unset($block->_first);
unset($block->_last);
}
if (trim($output) != '') {
// This is the area fallback template list
$fallback = array($context . '.area.' . $area, $context . '.area', 'area.' . $area, 'area');
$this->content = $output;
$newoutput = $this->display_fallback($fallback, 'fetch');
if ($newoutput !== false) {
$output = $newoutput;
}
}
$this->area = '';
if (isset($context)) {
array_pop($this->context);
}
return $output;
}