Commit 79ebfd09 authored by Dries's avatar Dries

- Patch #1013864 by agentrickard, JimmyAx: book navigation block fails with Node Access modules.

parent d107fb98
......@@ -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 hyphens 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);
......
......@@ -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 (_)'));
}
}
......@@ -279,10 +279,10 @@ function book_block_view($delta = '') {
}
elseif ($current_bid) {
// Only display this block when the user is browsing a book.
$select = db_select('node');
$select->addField('node', 'title');
$select->condition('nid', $node->book['bid']);
$select->addTag('node_access');
$select = db_select('node', 'n')
->fields('n', array('title'))
->condition('nid', $node->book['bid'])
->addTag('node_access');
$title = $select->execute()->fetchField();
// Only show the block if the user has view access for the top-level node.
if ($title) {
......
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