function _context_ui_get_blocks in Context 5
Same name and namespace in other branches
- 6 context_ui/context_ui.admin.inc \_context_ui_get_blocks()
- 6.2 context_ui/context_ui.admin.inc \_context_ui_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.
3 calls to _context_ui_get_blocks()
- context_ui_form in context_ui/
context_ui_admin.inc - Generates the omnibus context definition editing form. Note: submission and validation handlers are in context_ui_admin.inc
- context_ui_form_process in context_ui/
context_ui_admin.inc - Produces a context object from submitted form values.
- theme_context_ui_block_ui in context_ui/
context_ui_admin.inc - Generates the AJAX enabled block administration portion of the context_ui admin form.
File
- context_ui/
context_ui_admin.inc, line 821
Code
function _context_ui_get_blocks($region = null, $context = null) {
global $theme_key;
static $block_info, $valid, $system_blocks;
// we don't static cache context blocks
$context_blocks = $blocks = array();
if (!$system_blocks) {
// initialize regions
foreach (system_region_list($theme_key) as $r => $l) {
$system_blocks[$r] = array();
}
// load blocks from database
$result = db_query("SELECT module, delta, weight, region, status FROM {blocks} WHERE theme = '%s' ORDER BY weight, module, delta", $theme_key);
while ($block = db_fetch_object($result)) {
// load block info
$block_info[$block->module] = isset($block_info[$block->module]) ? $block_info[$block->module] : module_invoke($block->module, 'block', 'list');
$block->label = $block_info[$block->module][$block->delta]['info'];
$block->type = 'system';
$block->bid = $block->module . '_' . $block->delta;
// add block to region
if ($block->region && $block->status) {
$system_blocks[$block->region][$block->bid] = $block;
}
else {
$system_blocks[0][$block->bid] = $block;
}
// mark block as available in DB
$valid[$block->module . "_" . $block->delta] = true;
}
}
// load system blocks into main block array
$blocks = $system_blocks;
// load context blocks if provided
if (is_object($context) && is_array($context->block)) {
// iterate over context-associated blocks
foreach ($context->block as $block) {
$block = (object) $block;
// check that this is a valid block
if ($valid[$block->module . "_" . $block->delta]) {
// if region has been specified, ensure that block belongs to it
if (!$region || isset($region) && $block->region == $region) {
// load block info
$block_info[$block->module] = $block_info[$block->module] ? $block_info[$block->module] : module_invoke($block->module, 'block', 'list');
$block->label = $block_info[$block->module][$block->delta]['info'];
$block->type = 'context_ui';
$block->bid = $block->module . '_' . $block->delta;
// add block to region
if ($block->region) {
$blocks[$block->region][$block->bid] = $block;
}
else {
$blocks[0][$block->bid] = $block;
}
}
}
}
}
foreach ($blocks as $r => $sort_region) {
if ($r !== 0) {
uasort($sort_region, "_context_ui_block_compare");
$blocks[$r] = $sort_region;
}
}
return $region ? $blocks[$region] : $blocks;
}