summaryrefslogtreecommitdiff
path: root/modules/block
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2013-12-30 11:45:54 -0500
committerDavid Rothstein <drothstein@gmail.com>2013-12-30 11:45:54 -0500
commit226fe6997057f1b2b58116e7bc35ffbcbaed726c (patch)
tree1269931e826fc88e43d574ea896b0c216b40e3bc /modules/block
parent6cd1aae9884952d2eb9750133c85c1c52c3ba26f (diff)
downloadbrdo-226fe6997057f1b2b58116e7bc35ffbcbaed726c.tar.gz
brdo-226fe6997057f1b2b58116e7bc35ffbcbaed726c.tar.bz2
Issue #1076132 by fizk, friesk, foxtrotcharlie, coolestdude1, David_Rothstein, skwashd, alexpott, tstoeckler | adaddinsane: Hook_block_view_MODULE_DELTA_alter fails with blocks that have a hyphen in the block delta.
Diffstat (limited to 'modules/block')
-rw-r--r--modules/block/block.module4
-rw-r--r--modules/block/block.test42
-rw-r--r--modules/block/tests/block_test.module22
3 files changed, 67 insertions, 1 deletions
diff --git a/modules/block/block.module b/modules/block/block.module
index 3a988de2c..dde26ea8e 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -880,9 +880,11 @@ function _block_render_blocks($region_blocks) {
else {
$array = module_invoke($block->module, 'block_view', $block->delta);
+ // Valid PHP function names cannot contain hyphens.
+ $delta = str_replace('-', '_', $block->delta);
// Allow modules to modify the block before it is viewed, via either
// hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter().
- drupal_alter(array('block_view', "block_view_{$block->module}_{$block->delta}"), $array, $block);
+ drupal_alter(array('block_view', "block_view_{$block->module}_{$delta}"), $array, $block);
if (isset($cid)) {
cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY);
diff --git a/modules/block/block.test b/modules/block/block.test
index 11d070993..c1afec4bf 100644
--- a/modules/block/block.test
+++ b/modules/block/block.test
@@ -753,6 +753,48 @@ class BlockTemplateSuggestionsUnitTest extends DrupalUnitTestCase {
}
/**
+ * Tests for hook_block_view_MODULE_DELTA_alter().
+ */
+class BlockViewModuleDeltaAlterWebTest extends DrupalWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Block view module delta alter',
+ 'description' => 'Test the hook_block_view_MODULE_DELTA_alter() hook.',
+ 'group' => 'Block',
+ );
+ }
+
+ public function setUp() {
+ parent::setUp(array('block_test'));
+ }
+
+ /**
+ * Tests that the alter hook is called, even if the delta contains a hyphen.
+ */
+ public function testBlockViewModuleDeltaAlter() {
+ $block = new stdClass;
+ $block->module = 'block_test';
+ $block->delta = 'test_underscore';
+ $block->title = '';
+ $render_array = _block_render_blocks(array('region' => $block));
+ $render = array_pop($render_array);
+ $test_underscore = $render->content['#markup'];
+ $this->assertEqual($test_underscore, 'hook_block_view_MODULE_DELTA_alter', 'Found expected altered block content for delta with underscore');
+
+ $block = new stdClass;
+ $block->module = 'block_test';
+ $block->delta = 'test-hyphen';
+ $block->title = '';
+ $render_array = _block_render_blocks(array('region' => $block));
+ $render = array_pop($render_array);
+ $test_hyphen = $render->content['#markup'];
+ $this->assertEqual($test_hyphen, 'hook_block_view_MODULE_DELTA_alter', 'Hyphens (-) in block delta were replaced by underscore (_)');
+ }
+
+}
+
+/**
* Tests that hidden regions do not inherit blocks when a theme is enabled.
*/
class BlockHiddenRegionTestCase extends DrupalWebTestCase {
diff --git a/modules/block/tests/block_test.module b/modules/block/tests/block_test.module
index 5e06d5cf5..475ebc895 100644
--- a/modules/block/tests/block_test.module
+++ b/modules/block/tests/block_test.module
@@ -22,6 +22,14 @@ function block_test_block_info() {
'cache' => variable_get('block_test_caching', DRUPAL_CACHE_PER_ROLE),
);
+ $blocks['test_underscore'] = array(
+ 'info' => t('Test underscore'),
+ );
+
+ $blocks['test-hyphen'] = array(
+ 'info' => t('Test hyphen'),
+ );
+
$blocks['test_html_id'] = array(
'info' => t('Test block html id'),
);
@@ -34,3 +42,17 @@ function block_test_block_info() {
function block_test_block_view($delta = 0) {
return array('content' => variable_get('block_test_content', ''));
}
+
+/**
+ * Implements hook_block_view_MODULE_DELTA_alter().
+ */
+function block_test_block_view_block_test_test_underscore_alter(&$data, $block) {
+ $data['content'] = 'hook_block_view_MODULE_DELTA_alter';
+}
+
+/**
+ * Implements hook_block_view_MODULE_DELTA_alter().
+ */
+function block_test_block_view_block_test_test_hyphen_alter(&$data, $block) {
+ $data['content'] = 'hook_block_view_MODULE_DELTA_alter';
+}