diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-04-26 14:10:40 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-04-26 14:10:40 +0000 |
commit | b8664945dc3cbbb25f33b7664306739f96cde5b9 (patch) | |
tree | a854ebfe74ee8ae5f3035175ce276388fc01b93e /modules/block | |
parent | b94665f5aec34875c61ac28db847b104026b429e (diff) | |
download | brdo-b8664945dc3cbbb25f33b7664306739f96cde5b9.tar.gz brdo-b8664945dc3cbbb25f33b7664306739f96cde5b9.tar.bz2 |
- Patch #710172 by alexpott, Pasqualle: HTML ids for blocks should not contain underscores.
Diffstat (limited to 'modules/block')
-rw-r--r-- | modules/block/block.module | 3 | ||||
-rw-r--r-- | modules/block/block.test | 38 | ||||
-rw-r--r-- | modules/block/block.tpl.php | 3 | ||||
-rw-r--r-- | modules/block/tests/block_test.module | 4 |
4 files changed, 47 insertions, 1 deletions
diff --git a/modules/block/block.module b/modules/block/block.module index efcb6ef07..93f4389e4 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -872,6 +872,9 @@ function template_preprocess_block(&$variables) { $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->region; $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->module; $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->module . '__' . $variables['block']->delta; + + // Create a valid HTML ID and make sure it is unique. + $variables['block_html_id'] = drupal_html_id('block-' . $variables['block']->module . '-' . $variables['block']->delta); } /** diff --git a/modules/block/block.test b/modules/block/block.test index 417a18d5f..0f9eaafe4 100644 --- a/modules/block/block.test +++ b/modules/block/block.test @@ -549,3 +549,41 @@ class BlockCacheTestCase extends DrupalWebTestCase { } } } + +/** + * Test block HTML id validity. + */ +class BlockHTMLIdTestCase extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => 'Block HTML id', + 'description' => 'Test block HTML id validity.', + 'group' => 'Block', + ); + } + + function setUp() { + parent::setUp('block_test'); + + // Create an admin user, log in and enable test blocks. + $this->admin_user = $this->drupalCreateUser(array('administer blocks', 'access administration pages')); + $this->drupalLogin($this->admin_user); + + // Enable our test block. + $edit['block_test_test_html_id[region]'] = 'sidebar_first'; + $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); + + // Make sure the block has some content so it will appear + $current_content = $this->randomName(); + variable_set('block_test_content', $current_content); + } + + /** + * Test valid HTML id. + */ + function testHTMLId() { + $this->drupalGet(''); + $this->assertRaw('block-block-test-test-html-id', t('HTML id for test block is valid.')); + } +} diff --git a/modules/block/block.tpl.php b/modules/block/block.tpl.php index d4ebf89cc..f3cf6440f 100644 --- a/modules/block/block.tpl.php +++ b/modules/block/block.tpl.php @@ -35,13 +35,14 @@ * - $is_front: Flags true when presented in the front page. * - $logged_in: Flags true when the current user is a logged-in member. * - $is_admin: Flags true when the current user is an administrator. + * - $block_html_id: A valid HTML ID and guaranteed unique. * * @see template_preprocess() * @see template_preprocess_block() * @see template_process() */ ?> -<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>> +<div id="<?php print $block_html_id; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>> <?php print render($title_prefix); ?> <?php if ($block->subject): ?> diff --git a/modules/block/tests/block_test.module b/modules/block/tests/block_test.module index b10994aaa..46c1aa755 100644 --- a/modules/block/tests/block_test.module +++ b/modules/block/tests/block_test.module @@ -13,6 +13,10 @@ function block_test_block_info() { $blocks['test_cache'] = array( 'info' => t('Test block caching'), ); + + $blocks['test_html_id'] = array( + 'info' => t('Test block html id'), + ); return $blocks; } |