diff --git a/blockgroup.module b/blockgroup.module index 529e834..d1e714e 100644 --- a/blockgroup.module +++ b/blockgroup.module @@ -260,7 +260,7 @@ function blockgroup_block_list_alter(&$blocks) { $group_regions = array(); foreach ($blocks as $bid => $block) { if ($block->module === 'blockgroup') { - $group_regions[blockgroup_region_for_blockgroup($blocks[$bid]->delta)] = $bid; + $group_regions[blockgroup_get_region($blocks[$bid]->delta)] = $bid; } } @@ -316,7 +316,7 @@ function blockgroup_block_list_alter(&$blocks) { function blockgroup_block_view($delta) { $block['content'] = array( '#type' => 'blockgroup_pullup', - '#key' => blockgroup_region_for_blockgroup($delta), + '#key' => blockgroup_get_region($delta), ); return $block; } @@ -342,13 +342,14 @@ function blockgroup_page_alter(&$page) { } } } + } - // If this is a blockgroup region, move it into $page['#blockgroups'] in - // order to prevent certain themes from messing with them. - if (blockgroup_region_is_blockgroup($region)) { - $page['#blockgroups'][$region] = $blocks; - unset($page[$region]); - } + // Move all blockgroup regions into $page['#blockgroups'] in order to prevent + // certain themes from messing with them. + $blockgroup_regions = array_intersect_key($page, blockgroup_region_list()); + foreach ($blockgroup_regions as $region => $blocks) { + $page['#blockgroups'][$region] = $blocks; + unset($page[$region]); } } @@ -376,7 +377,7 @@ function blockgroup_theme() { function blockgroup_preprocess_block(&$variables) { if ($variables['block']->module === 'blockgroup') { array_unshift($variables['theme_hook_suggestions'], 'block__blockgroup__default'); - $variables['region'] = blockgroup_region_for_blockgroup($variables['block']->delta); + $variables['region'] = blockgroup_get_region($variables['block']->delta); // Allow the use of a region--blockgroup.tpl.php template that will affect // all block group regions. @@ -391,7 +392,8 @@ function blockgroup_preprocess_block(&$variables) { * Insert 'blockgroup' into classes array for regions defined by this module. */ function blockgroup_preprocess_region(&$variables) { - if (blockgroup_region_is_blockgroup($variables['region'])) { + $blockgroup_regions = blockgroup_region_list(); + if (isset($blockgroup_regions[$variables['region']])) { $variables['classes_array'][] = 'blockgroup'; } } @@ -418,7 +420,7 @@ function blockgroup_form_block_admin_display_form_alter(&$form, &$form_state) { $blockgroups = blockgroup_list(); foreach ($blockgroups as $delta => $title) { - $key = blockgroup_region_for_blockgroup($delta); + $key = blockgroup_get_region($delta); $region_anchor = drupal_clean_css_identifier('region-' . $key); $block_anchor = drupal_clean_css_identifier('block-' . $key); @@ -474,10 +476,12 @@ function blockgroup_list() { * Return a list of regions created by block groups. */ function blockgroup_region_list() { - $regions = array(); + $regions = &drupal_static(__FUNCTION__); - foreach (blockgroup_list() as $delta => $title) { - $regions[blockgroup_region_for_blockgroup($delta)] = t('Block group: @title', array('@title' => $title)); + if (!isset($regions)) { + foreach (blockgroup_list() as $delta => $title) { + $regions[blockgroup_get_region($delta)] = t('Block group: @title', array('@title' => $title)); + } } return $regions; @@ -538,6 +542,7 @@ function blockgroup_delete($blockgroup) { */ function blockgroup_rebuild_data() { drupal_static_reset('blockgroup_list'); + drupal_static_reset('blockgroup_region_list'); cache_clear_all(); @@ -547,20 +552,6 @@ function blockgroup_rebuild_data() { /** - * Tests whether a given region is defined by blockgroup. - * - * @param string $region_key - * The machine name of a region. - * - * @returns bool - * TRUE if this region is defined by a block group, FALSE otherwise. - */ -function blockgroup_region_is_blockgroup($region_key) { - return substr($region_key, 0, 11) === 'blockgroup_'; -} - - -/** * Returns the region name defined by the given blockgroup. * * @param string $delta @@ -569,6 +560,6 @@ function blockgroup_region_is_blockgroup($region_key) { * @returns string * The machine name of the region. */ -function blockgroup_region_for_blockgroup($delta) { +function blockgroup_get_region($delta) { return 'blockgroup_' . $delta; }