function context_reaction_block::get_blocks in Context 6.3
Same name and namespace in other branches
- 6 plugins/context_reaction_block.inc \context_reaction_block::get_blocks()
- 7.3 plugins/context_reaction_block.inc \context_reaction_block::get_blocks()
Helper function to generate a list of blocks from a specified region. If provided a context object, will generate a full list of blocks for that region distinguishing between system blocks and context-provided blocks.
Parameters
$region: The string identifier for a theme region. e.g. "left"
$context: A context object.
Return value
A keyed (by "module_delta" convention) array of blocks.
6 calls to context_reaction_block::get_blocks()
- context_reaction_block::block_list in plugins/
context_reaction_block.inc - An alternative version of block_list() that provides any context enabled blocks.
- context_reaction_block::editor_form in plugins/
context_reaction_block.inc - Context editor form for blocks.
- context_reaction_block::max_block_weight in plugins/
context_reaction_block.inc - Generate the safe weight range for a block being added to a region such that there are enough potential unique weights to support all blocks.
- context_reaction_block::options_form in plugins/
context_reaction_block.inc - Options form.
- context_reaction_block::options_form_submit in plugins/
context_reaction_block.inc - Options form submit handler.
File
- plugins/
context_reaction_block.inc, line 414
Class
- context_reaction_block
- Expose blocks as context reactions.
Code
function get_blocks($region = NULL, $context = NULL, $reset = FALSE) {
static $block_info;
if (!isset($block_info) || $reset) {
$block_info = array();
if (!$reset) {
$block_info = context_cache_get('block_info');
}
if (empty($block_info)) {
$block_info = array();
foreach (module_implements('block') as $module) {
$module_blocks = module_invoke($module, 'block', 'list');
if (!empty($module_blocks)) {
foreach ($module_blocks as $delta => $block) {
$block = (object) $block;
$block->module = $module;
$block->delta = $delta;
$block->bid = "{$block->module}-{$block->delta}";
$block_info[$block->bid] = $block;
}
}
}
context_cache_set('block_info', $block_info);
}
// Allow other modules that may declare blocks dynamically to alter
// this list.
drupal_alter('context_block_info', $block_info);
// Gather only region info from the database.
$theme_key = variable_get('theme_default', 'garland');
$result = db_query("SELECT module,weight,delta,region,status FROM {blocks} WHERE theme = '%s' ORDER BY weight ASC", $theme_key);
while ($row = db_fetch_object($result)) {
if ($row->status && isset($block_info["{$row->module}-{$row->delta}"])) {
$block_info["{$row->module}-{$row->delta}"]->weight = $row->weight;
$block_info["{$row->module}-{$row->delta}"]->region = $row->region;
}
}
}
$blocks = array();
// No region specified, provide all blocks.
if (!isset($region)) {
$blocks = $block_info;
}
else {
foreach ($block_info as $bid => $block) {
if (isset($block->region) && $block->region == $region) {
$blocks[$bid] = $block;
}
}
}
// Add context blocks if provided.
if (is_object($context) && ($options = $this
->fetch_from_context($context))) {
if (!empty($options['blocks'])) {
foreach ($options['blocks'] as $block) {
if (isset($block_info["{$block['module']}-{$block['delta']}"]) && (!isset($region) || !empty($region) && $block['region'] == $region)) {
$context_block = $block_info["{$block['module']}-{$block['delta']}"];
$context_block->weight = $block['weight'];
$context_block->region = $block['region'];
$context_block->context = $context->name;
$blocks[$context_block->bid] = $context_block;
}
}
}
uasort($blocks, array(
'context_reaction_block',
'block_sort',
));
}
return $blocks;
}