diff options
Diffstat (limited to 'modules/block/block.module')
-rw-r--r-- | modules/block/block.module | 77 |
1 files changed, 51 insertions, 26 deletions
diff --git a/modules/block/block.module b/modules/block/block.module index 5e0de24d0..4cba11220 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -29,13 +29,16 @@ function block_help($path, $arg) { $output .= '<li>' . t('some dynamic blocks, such as those generated by modules, will be displayed only on certain pages.') . '</li></ul>'; $output .= '<p>' . t('For more information, see the online handbook entry for <a href="@block">Block module</a>.', array('@block' => 'http://drupal.org/handbook/modules/block/')) . '</p>'; return $output; - case 'admin/structure/block': - $output = '<p>' . t('This page provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions. Since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis. Remember that your changes will not be saved until you click the <em>Save blocks</em> button at the bottom of the page.') . '</p>'; - $output .= '<p>' . t('Click the <em>configure</em> link next to each block to configure its specific title and visibility settings. Use the <a href="@add-block">add block page</a> to create a custom block.', array('@add-block' => url('admin/structure/block/add'))) . '</p>'; - return $output; case 'admin/structure/block/add': return '<p>' . t('Use this page to create a new custom block. New blocks are disabled by default, and must be moved to a region on the <a href="@blocks">blocks administration page</a> to be visible.', array('@blocks' => url('admin/structure/block'))) . '</p>'; } + if ($arg[0] == 'admin' && $arg[1] == 'structure' && $arg['2'] == 'block' && (empty($arg[3]) || $arg[3] == 'list')) { + $demo_theme = !empty($arg[4]) ? $arg[4] : variable_get('theme_default', 'garland'); + $themes = list_themes(); + $output = '<p>' . t('This page provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions. Since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis. Remember that your changes will not be saved until you click the <em>Save blocks</em> button at the bottom of the page. Click the <em>configure</em> link next to each block to configure its specific title and visibility settings.') . '</p>'; + $output .= '<p>' . l(t('Demonstrate block regions (@theme)', array('@theme' => $themes[$demo_theme]->info['name'])), 'admin/structure/block/demo/' . $demo_theme) . '</p>'; + return $output; + } } /** @@ -71,12 +74,13 @@ function block_permission() { * Implement hook_menu(). */ function block_menu() { + $default_theme = variable_get('theme_default', 'garland'); $items['admin/structure/block'] = array( 'title' => 'Blocks', 'description' => 'Configure what block content appears in your site\'s sidebars and other regions.', 'page callback' => 'block_admin_display', + 'page arguments' => array($default_theme), 'access arguments' => array('administer blocks'), - 'theme callback' => '_block_custom_theme', 'file' => 'block.admin.inc', ); $items['admin/structure/block/list'] = array( @@ -115,13 +119,21 @@ function block_menu() { 'type' => MENU_LOCAL_ACTION, 'file' => 'block.admin.inc', ); - $default = variable_get('theme_default', 'garland'); foreach (list_themes() as $key => $theme) { $items['admin/structure/block/list/' . $key] = array( 'title' => check_plain($theme->info['name']), 'page arguments' => array($key), - 'type' => $key == $default ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, - 'weight' => $key == $default ? -10 : 0, + 'type' => $key == $default_theme ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, + 'weight' => $key == $default_theme ? -10 : 0, + 'access callback' => '_block_themes_access', + 'access arguments' => array($theme), + 'file' => 'block.admin.inc', + ); + $items['admin/structure/block/demo/' . $key] = array( + 'title' => check_plain($theme->info['name']), + 'page callback' => 'block_admin_demo', + 'page arguments' => array($key), + 'type' => MENU_CALLBACK, 'access callback' => '_block_themes_access', 'access arguments' => array($theme), 'theme callback' => '_block_custom_theme', @@ -200,7 +212,7 @@ function block_block_view($delta = 0, $edit = array()) { } /** - * Implement hook_page_alter(). + * Implement hook_page_build(). * * Render blocks into their regions. */ @@ -213,19 +225,23 @@ function block_page_build(&$page) { // Populate all block regions $all_regions = system_region_list($theme); - // Load all region content assigned via blocks. - foreach (array_keys($all_regions) as $region) { - $page[$region] = array(); - // Assign blocks to region. - if ($blocks = block_get_blocks_by_region($region)) { - $page[$region] = $blocks; + $item = menu_get_item(); + if ($item['path'] != 'admin/structure/block/demo/' . $theme) { + // Load all region content assigned via blocks. + foreach (array_keys($all_regions) as $region) { + $page[$region] = array(); + // Assign blocks to region. + if ($blocks = block_get_blocks_by_region($region)) { + $page[$region] = $blocks; + } } - - // Append region description if we are rendering the block admin page. + } + else { + // Append region description if we are rendering the regions demo page. $item = menu_get_item(); - if ($item['path'] == 'admin/structure/block') { - $visible_regions = system_region_list($theme, REGIONS_VISIBLE); - if (isset($visible_regions[$region])) { + if ($item['path'] == 'admin/structure/block/demo/' . $theme) { + $visible_regions = array_keys(system_region_list($theme, REGIONS_VISIBLE)); + foreach ($visible_regions as $region) { $description = '<div class="block-region">' . $all_regions[$region] . '</div>'; $page[$region]['block_description'] = array( '#markup' => $description, @@ -277,16 +293,25 @@ function _block_get_renderable_array($list = array()) { /** * Update the 'block' DB table with the blocks currently exported by modules. * + * @param $theme + * The theme to rehash blocks for. If not provided, defaults to the currently + * used theme. + * * @return * Blocks currently exported by modules. */ -function _block_rehash() { +function _block_rehash($theme = NULL) { global $theme_key; - + drupal_theme_initialize(); + if (!isset($theme)) { + // If theme is not specifically set, rehash for the current theme. + $theme = $theme_key; + } + $old_blocks = array(); - $result = db_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $theme_key)); + $result = db_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $theme)); foreach ($result as $old_block) { $old_block = is_object($old_block) ? get_object_vars($old_block) : $old_block; $old_blocks[$old_block['module']][$old_block['delta']] = $old_block; @@ -294,7 +319,7 @@ function _block_rehash() { $blocks = array(); // Valid region names for the theme. - $regions = system_region_list($theme_key); + $regions = system_region_list($theme); foreach (module_implements('block_info') as $module) { $module_blocks = module_invoke($module, 'block_info'); @@ -304,7 +329,7 @@ function _block_rehash() { // If it's a new block, add identifiers. $block['module'] = $module; $block['delta'] = $delta; - $block['theme'] = $theme_key; + $block['theme'] = $theme; if (!isset($block['pages'])) { // {block}.pages is type 'text', so it cannot have a // default value, and not null, so we need to provide @@ -349,7 +374,7 @@ function _block_rehash() { db_delete('block') ->condition('module', $module) ->condition('delta', $delta) - ->condition('theme', $theme_key) + ->condition('theme', $theme) ->execute(); } } |