Posted by jenlampton on February 19, 2012 at 6:46am
3 followers
| Project: | AdaptiveTheme |
| Version: | 7.x-2.x-dev |
| Component: | CSS/HTML |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Problem/Motivation
For system menus ('navigation', 'main-menu', 'management', 'user-menu') If someone adds both a block--menu.tpl.php file and a block--system--menu-name.tpl.php file, the later, though more specific, will never be used.
The problem is that block__menu was added to the end of the theme_hook_suggestions array, meaning it will take precedence.
Proposed resolution
Add block__menu to the beginning of the array, or even better, just before block__system.
| Attachment | Size |
|---|---|
| menu-block-theme.png | 46.74 KB |
Comments
#1
patchy patchy
#2
hmmm, I know this happens but in practice I never worried about it and no one ever mentioned it :P
I'm not sure array_unshift gives us what we really want, its a solution but it means if someone adds a simple block--region tpl the markup gets nuked for the menu blocks and reduces the semantics - which I would say is worse bug, especially if you are relying on the markup for CSS etc (which you shouldn't, but people do...).
Probably, looking at this with fresh eyes, the whole way this works is rather weak. The only real reason I wanted to use the block--menu template for those menus is to get generic markup for all those blocks and use the nav element. Perhaps there is a better way, perhaps even removing that template[suggestion] and generating the tag for use in block.tpl.php. I can see a number of solution, will need to think about it and do some testing.
Any other suggestions welcome, even right outside the box (the best kind).
I need to rethink this a bit. Good bug report, I can see we can make improvements.
Cheers.
#3
What if we got rid of all the other block templates and did something like this instead, this would solve the issue as well by 1) simply not using that suggestion in the theme, and 2) provide at least two more powerful suggestions one can use if you do:
<?php
// Generate the wrapper element, if there's a title use <section>, otherwise use <div>.
$vars['block']->subject ? $vars['tag'] = 'section' : $vars['tag'] = 'div';
// Use nav element for menu blocks and provide a "weak suggestion" for all of them
$nav_blocks = array('navigation', 'main-menu', 'management', 'user-menu');
if (in_array($vars['block']->delta, $nav_blocks)) {
$vars['tag'] = 'nav';
array_unshift($vars['theme_hook_suggestions'], 'block__menu');
}
$nav_modules = array('superfish', 'nice_menus');
if (in_array($vars['block']->module, $nav_modules)) {
$vars['tag'] = 'nav';
array_unshift($vars['theme_hook_suggestions'], 'block__menu');
}
// Hide the title for blocks in the menu bar
if ($vars['block']->region == 'menu_bar') {
$vars['title_attributes_array']['class'][] = 'element-invisible';
}
// Provide additional suggestions so the block__menu suggestion can be overridden easily and with granularity
$vars['theme_hook_suggestions'][] = 'block__' . $vars['block']->region . '__' . $vars['block']->module;
$vars['theme_hook_suggestions'][] = 'block__' . $vars['block']->region . '__' . $vars['block']->delta;
?>
Provides this...
#4
This is now fixed, the suggestions are weak and easily overridden.