summaryrefslogtreecommitdiff
path: root/modules/block
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-05-24 14:00:57 -0700
committerwebchick <webchick@24967.no-reply.drupal.org>2011-05-24 14:00:57 -0700
commitc09a969d96e70cd2470849fc159d74f54b552181 (patch)
treeb1a8e9bf5b83c6d6a16f3994cf8137ae04447945 /modules/block
parentfef11ae71ec1198b6eccde87aff0aec971d5debf (diff)
downloadbrdo-c09a969d96e70cd2470849fc159d74f54b552181.tar.gz
brdo-c09a969d96e70cd2470849fc159d74f54b552181.tar.bz2
Issue #1021270 by larowlan, wojtha: Fixed Blocks for custom menus are impossible to theme.
Diffstat (limited to 'modules/block')
-rw-r--r--modules/block/block.module10
-rw-r--r--modules/block/block.test42
2 files changed, 51 insertions, 1 deletions
diff --git a/modules/block/block.module b/modules/block/block.module
index 2f7e372fe..73eba3311 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -943,7 +943,15 @@ 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;
+ // Hyphens (-) and underscores (_) play a special role in theme suggestions.
+ // Theme suggestions should only contain underscores, because within
+ // drupal_find_theme_templates(), underscores are converted to hyphens to
+ // match template file names, and then converted back to underscores to match
+ // pre-processing and other function names. So if your theme suggestion
+ // contains a hyphen, it will end up as an underscore after this conversion,
+ // and your function names won't be recognized. So, we need to convert
+ // hyphens to underscores in block deltas for the theme suggestions.
+ $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->module . '__' . strtr($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 af118a940..022bf3830 100644
--- a/modules/block/block.test
+++ b/modules/block/block.test
@@ -666,3 +666,45 @@ class BlockHTMLIdTestCase extends DrupalWebTestCase {
$this->assertRaw('block-block-test-test-html-id', t('HTML id for test block is valid.'));
}
}
+
+
+/**
+ * Unit tests for template_preprocess_block().
+ */
+class BlockTemplateSuggestionsUnitTest extends DrupalUnitTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Block template suggestions',
+ 'description' => 'Test the template_preprocess_block() function.',
+ 'group' => 'Block',
+ );
+ }
+
+ /**
+ * Test if template_preprocess_block() handles the suggestions right.
+ */
+ function testBlockThemeHookSuggestions() {
+ // Define block delta with underscore to be preprocessed
+ $block1 = new stdClass();
+ $block1->module = 'block';
+ $block1->delta = 'underscore_test';
+ $block1->region = 'footer';
+ $variables1 = array();
+ $variables1['elements']['#block'] = $block1;
+ $variables1['elements']['#children'] = '';
+ template_preprocess_block($variables1);
+ $this->assertEqual($variables1['theme_hook_suggestions'], array('block__footer', 'block__block', 'block__block__underscore_test'), t('Found expected block suggestions for delta with underscore'));
+
+ // Define block delta with hyphens to be preprocessed. Hyphens should be
+ // replaced with underscores.
+ $block2 = new stdClass();
+ $block2->module = 'block';
+ $block2->delta = 'hyphen-test';
+ $block2->region = 'footer';
+ $variables2 = array();
+ $variables2['elements']['#block'] = $block2;
+ $variables2['elements']['#children'] = '';
+ template_preprocess_block($variables2);
+ $this->assertEqual($variables2['theme_hook_suggestions'], array('block__footer', 'block__block', 'block__block__hyphen_test'), t('Hyphens (-) in block delta were replaced by underscore (_)'));
+ }
+}