Commit b8664945 authored by Dries's avatar Dries

- Patch #710172 by alexpott, Pasqualle: HTML ids for blocks should not contain underscores.

parent b94665f5
......@@ -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);
}
/**
......
......@@ -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.'));
}
}
......@@ -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): ?>
......
......@@ -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;
}
......
<?php
// $Id$
?>
<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<div id="<?php print $block_html_id; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<?php print render($title_prefix); ?>
<?php if (!empty($block->subject)): ?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment