function _fe_block_get_blocks in Features Extra 7
Returns the blocks currently exported by modules.
This is derived from _block_rehash().
Parameters
string $theme: The theme to retrieve blocks for. If not provided, defaults to the currently used theme.
Return value
array Blocks currently exported by modules.
2 calls to _fe_block_get_blocks()
- fe_block_settings_features_export_options in fe_block/
fe_block.module - Implements hook_features_export_options().
- _fe_block_info_by_theme in fe_block/
fe_block.module - Returns the block definitions for a specific theme.
File
- fe_block/
fe_block.module, line 321 - Provide features components for exporting core blocks and settings.
Code
function _fe_block_get_blocks($theme = NULL) {
global $theme_key;
$blocks = array();
drupal_theme_initialize();
if (!isset($theme)) {
// If theme is not specifically set, rehash for the current theme.
$theme = $theme_key;
}
$regions = system_region_list($theme);
// These are the blocks defined by code and modified by the database.
$current_blocks = array();
$or = db_or();
// Gather the blocks defined by modules.
foreach (module_implements('block_info') as $module) {
$module_blocks = module_invoke($module, 'block_info');
foreach ($module_blocks as $delta => $block) {
// Compile a condition to retrieve this block from the database.
$condition = db_and()
->condition('module', $module)
->condition('delta', $delta);
$or
->condition($condition);
// Add identifiers.
$block['module'] = $module;
$block['delta'] = $delta;
$block['theme'] = $theme;
$current_blocks[$module][$delta] = $block;
}
}
// Retrieve database settings for all blocks that are defined by modules.
$code_blocks = $current_blocks;
$database_blocks = db_select('block', 'b')
->fields('b')
->condition($or)
->condition('theme', $theme)
->execute();
foreach ($database_blocks as $block) {
// Preserve info which is not in the database.
$block->info = $current_blocks[$block->module][$block->delta]['info'];
// The cache mode can only by set from hook_block_info(), so that has
// precedence over the database's value.
if (isset($current_blocks[$block->module][$block->delta]['cache'])) {
$block->cache = $current_blocks[$block->module][$block->delta]['cache'];
}
// Blocks stored in the database override the blocks defined in code.
$current_blocks[$block->module][$block->delta] = get_object_vars($block);
}
drupal_alter('block_info', $current_blocks, $theme, $code_blocks);
foreach ($current_blocks as $module => $module_blocks) {
foreach ($module_blocks as $delta => $block) {
if (!isset($block['pages'])) {
// {block}.pages is type 'text', so it cannot have a
// default value, and not null, so we need to provide
// value if the module did not.
$block['pages'] = '';
}
// Make sure weight is set.
if (!isset($block['weight'])) {
$block['weight'] = 0;
}
// Disable blocks that are not assigned to a region in the theme.
if (!empty($block['region']) && $block['region'] != BLOCK_REGION_NONE && !isset($regions[$block['region']]) && !empty($block['status']) && $block['status'] == 1) {
// Disabled modules are moved into the BLOCK_REGION_NONE later so no
// need to move the block to another region.
$block['status'] = 0;
}
// Set region to none if not enabled and make sure status is set.
if (empty($block['status'])) {
$block['status'] = 0;
$block['region'] = BLOCK_REGION_NONE;
}
// Add to the list of blocks we return.
$blocks[] = $block;
}
}
return $blocks;
}