diff options
-rw-r--r-- | modules/block/block.admin.inc | 61 | ||||
-rw-r--r-- | modules/block/block.module | 77 | ||||
-rw-r--r-- | modules/block/block.test | 5 | ||||
-rw-r--r-- | modules/system/system.test | 3 |
4 files changed, 102 insertions, 44 deletions
diff --git a/modules/block/block.admin.inc b/modules/block/block.admin.inc index a1e65457d..4f5840513 100644 --- a/modules/block/block.admin.inc +++ b/modules/block/block.admin.inc @@ -7,11 +7,34 @@ */ /** + * Menu callback for admin/structure/block/demo. + */ +function block_admin_demo($theme = NULL) { + drupal_add_css(drupal_get_path('module', 'block') . '/block.css', array('preprocess' => FALSE)); + return ''; +} + +/** * Menu callback for admin/structure/block. + * + * @param $theme + * The theme to display the administration page for. If not provided, defaults + * to the currently used theme. */ function block_admin_display($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; + } + // Fetch and sort blocks. - $blocks = _block_rehash(); + $blocks = _block_rehash($theme); + $compare_theme = &drupal_static('_block_compare:theme'); + $compare_theme = $theme; usort($blocks, '_block_compare'); return drupal_get_form('block_admin_display_form', $blocks, $theme); @@ -20,12 +43,11 @@ function block_admin_display($theme = NULL) { /** * Generate main blocks administration form. */ -function block_admin_display_form($form, &$form_state, $blocks, $theme = NULL) { - global $theme_key; +function block_admin_display_form($form, &$form_state, $blocks, $theme) { drupal_add_css(drupal_get_path('module', 'block') . '/block.css', array('preprocess' => FALSE)); - $block_regions = system_region_list($theme_key, REGIONS_VISIBLE) + array(BLOCK_REGION_NONE => '<' . t('none') . '>'); + $block_regions = system_region_list($theme, REGIONS_VISIBLE) + array(BLOCK_REGION_NONE => '<' . t('none') . '>'); // Weights range from -delta to +delta, so delta should be at least half // of the amount of blocks present. This makes sure all blocks in the same @@ -33,7 +55,8 @@ function block_admin_display_form($form, &$form_state, $blocks, $theme = NULL) { $weight_delta = round(count($blocks) / 2); // Build the form tree. - $form['#action'] = arg(4) ? url('admin/structure/block/list/' . $theme_key) : url('admin/structure/block'); + $form['edited_theme'] = array('#type' => 'value', '#value' => $theme); + $form['#action'] = arg(4) ? url('admin/structure/block/list/' . $theme) : url('admin/structure/block'); $form['#tree'] = TRUE; foreach ($blocks as $i => $block) { @@ -51,7 +74,7 @@ function block_admin_display_form($form, &$form_state, $blocks, $theme = NULL) { ); $form[$key]['theme'] = array( '#type' => 'hidden', - '#value' => $theme_key, + '#value' => $theme, ); $form[$key]['weight'] = array( '#type' => 'weight', @@ -115,11 +138,18 @@ function block_admin_display_form_submit($form, &$form_state) { */ function _block_compare($a, $b) { global $theme_key; - $regions = &drupal_static(__FUNCTION__); - + + // Theme should be set before calling this function, or the current theme + // is being used. + $theme = &drupal_static(__FUNCTION__ . ':theme'); + if (!isset($theme)) { + $theme = $theme_key; + } + + $regions = &drupal_static(__FUNCTION__ . ':regions'); // We need the region list to correctly order by region. if (!isset($regions)) { - $regions = array_flip(array_keys(system_region_list($theme_key))); + $regions = array_flip(array_keys(system_region_list($theme))); $regions[BLOCK_REGION_NONE] = count($regions); } @@ -186,22 +216,22 @@ function block_admin_configure($form, &$form_state, $module = NULL, $delta = 0) $theme_default = variable_get('theme_default', 'garland'); // Create a select list for each theme - foreach (list_themes() as $theme_key => $theme) { + foreach (list_themes() as $key => $theme) { // Only display enabled themes if ($theme->status) { $region = db_query("SELECT region FROM {block} WHERE module = :module AND delta = :delta AND theme = :theme", array( ':module' => $module, ':delta' => $delta, - ':theme' => $theme_key, + ':theme' => $key, ))->fetchField(); - $form['regions'][$theme_key] = array( + $form['regions'][$key] = array( '#type' => 'select', '#title' => t('!theme region', array('!theme' => $theme->info['name'])), '#default_value' => (!empty($region) ? $region : BLOCK_REGION_NONE), '#options' => array(BLOCK_REGION_NONE => t('Disabled')) + $theme->info['regions'], - '#expandable' => ($theme_key !== $theme_default), - '#weight' => ($theme_key == $theme_default ? 9 : 10), + '#expandable' => ($key !== $theme_default), + '#weight' => ($key == $theme_default ? 9 : 10), ); } } @@ -513,9 +543,8 @@ function block_custom_block_delete_submit($form, &$form_state) { * @see theme_block_admin_display() */ function template_preprocess_block_admin_display_form(&$variables) { - global $theme_key; - $block_regions = system_region_list($theme_key, REGIONS_VISIBLE); + $block_regions = system_region_list($variables['form']['edited_theme']['#value'], REGIONS_VISIBLE); $variables['block_regions'] = $block_regions + array(BLOCK_REGION_NONE => t('Disabled')); foreach ($block_regions as $key => $value) { 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(); } } diff --git a/modules/block/block.test b/modules/block/block.test index 02b774ca8..8bfdaf5bb 100644 --- a/modules/block/block.test +++ b/modules/block/block.test @@ -59,6 +59,7 @@ class BlockTestCase extends DrupalWebTestCase { } // Delete the created custom block & verify that it's been deleted and no longer appearing on the page. + $this->drupalGet('admin/structure/block'); $this->clickLink(t('delete')); $this->drupalPost('admin/structure/block/delete/' . $bid, array(), t('Delete')); $this->assertRaw(t('The block %title has been removed.', array('%title' => $custom_block['info'])), t('Custom block successfully deleted.')); @@ -84,6 +85,7 @@ class BlockTestCase extends DrupalWebTestCase { $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); // Confirm that the custom block is being displayed using configured text format. + $this->drupalGet('node'); $this->assertRaw('<h1>Full HTML</h1>', t('Custom block successfully being displayed using Full HTML.')); // Confirm that a user without access to Full HTML can not see the body field, @@ -96,6 +98,7 @@ class BlockTestCase extends DrupalWebTestCase { $this->assertNoText(t('Please ensure that each block description is unique.')); // Confirm that the custom block is still being displayed using configured text format. + $this->drupalGet('node'); $this->assertRaw('<h1>Full HTML</h1>', t('Custom block successfully being displayed using Full HTML.')); } @@ -206,6 +209,7 @@ class BlockTestCase extends DrupalWebTestCase { $this->assertText(t('The block settings have been updated.'), t('Block successfully moved to %region_name region.', array( '%region_name' => $region['name']))); // Confirm that the block is being displayed. + $this->drupalGet('node'); $this->assertText(t($block['title']), t('Block successfully being displayed on the page.')); // Confirm that the custom block was found at the proper region. @@ -231,7 +235,6 @@ class NonDefaultBlockAdmin extends DrupalWebTestCase { $this->drupalLogin($admin_user); $this->drupalPost('admin/appearance', array('status[stark]' => 1), t('Save configuration')); $this->drupalGet('admin/structure/block/list/stark'); - $this->assertRaw('stark/layout.css', t('Stark CSS found')); } } diff --git a/modules/system/system.test b/modules/system/system.test index 226adff0f..9d792932f 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -979,9 +979,10 @@ class SystemBlockTestCase extends DrupalWebTestCase { $edit = array(); $edit['system_powered-by[region]'] = 'footer'; $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); - $this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.')); + $this->assertText(t('The block settings have been updated.'), t('Block successfully moved to footer region.')); // Confirm that the block is being displayed. + $this->drupalGet('node'); $this->assertRaw('id="block-system-powered-by"', t('Block successfully being displayed on the page.')); // Set the block to the disabled region. |