Hi
Thanks for simplemenu, it's allowed us to improve the user experience x10.
I've always hated what Tabs do to a design. On the site we've just done, I've hacked simplemenu to allow me to add an additional a section for tabs. My changes are all in simplemenu_get_menu()
...
// devel menu call unchanged.
$output .= simplemenu_get_devel();
// I added this bit so that mymodule_simplemenu_extend() would get called.
foreach (module_implements('simplemenu_extend') as $module) {
$func = $module .'_simplemenu_extend';
$output .= $func();
}
// finally the configured menu is added - no change.
$output .= $menu;
I can then utilize this hook to add the primary and secondary tabs into the simplemenu. It's a reasonable example of why giving control to other modules is useful - you could argue that the devel menu code could be moved to devel in this way (whether that is practical is another story).
My code:
/**
* Return local tabs, primary and secondary to the simplemenu
*/
function mymodule_simplemenu_extend() {
$output = '';
$local_tasks = menu_get_local_tasks();
$pid = menu_get_active_nontask_item();
$output = '';
if (count($local_tasks[$pid]['children'])) {
foreach ($local_tasks[$pid]['children'] as $mid) {
// $output .= theme('menu_local_task', $mid, menu_in_active_trail($mid), TRUE);
$links[] = menu_item_link($mid);
}
}
if (count($local_tasks[$pid]['children'])) {
foreach ($local_tasks[$pid]['children'] as $mid) {
if (menu_in_active_trail($mid) && count($local_tasks[$mid]['children']) > 1) {
$links[] = '<li>------</li>';
foreach ($local_tasks[$mid]['children'] as $cid) {
$links[] = menu_item_link($cid);
}
}
}
}
if (count($links)) {
$output = '<li class="expanded"><a href="'. url($_GET['q']) .'">'. t('Current page') .'</a><ul>';
$output .= '<li class="leaf">'. implode($links, '</li><li class="leaf">') .'</li>';
$output .= '</ul></li>';
return $output;
}
return '';
}
my request
I don't think my hack of simplemenu is necessarily the best way to do it. All I'd ask is for a future version of simplemenu to allow some sort of pass out to other modules, or to the theme layer, to add additional sections. Anything, however simple, and in D5, please :)
Of course, if my code to insert the local tabs is considered useful, I'd not argue against it going into simplemenu. To understand what it does, on the blocks page you have two tabs: List and Add Block. Then in the secondard tabs you have a link to configure blocks for each theme. With the above code, I have a new top level item called "Current Page", and on the blocks page it looks like this:
Current page
List
Add Block
---------------
bluemarine settings
garland settings
pushbutton settings
....
Thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | simplemenu.hook_alter.patch | 6.59 KB | zroger |
Comments
Comment #1
zroger commentedThis looks like a great idea. I'll have to take another look at it.
Changing to 6.x, since 5 will see no more feature updates.
Comment #2
zroger commentedHere's a patch that adds the ability for the menu to be altered before it is rendered. I'd like to get some community feedback before committing since it changes quite a bit about the way the module works on the back end.
With this patch, a new hook is available to modules, hook_simplemenu_tree_alter. It uses the standard drupal_alter() mechanism for invoking this hook so it behaves the same way that hook_form_alter() and hook_link_alter() work. The patch uses this hook to add the devel links to the menu, so that is the best place to look for an example of how to use the hook.
And now a little about what changed in the backend...
Previously, the menu links were output using the Drupals menu_tree_output() function, which took a very complex menu tree structure and called several theme functions to build the rendered tree. There is now a function simplemenu_tree_output() which does the rendering without functions. The tree array parameter for this function is a much simpler tree than the menu tree array. simplemenu_tree_output() is largely based on theme_item_list(), so the tree array is the same as the $items array for an item_list. nested lists are placed in the 'children' index of an item. This is the tree structure that is passed to hook_simplemenu_tree_alter().
A side effect of using our own output function is that it no longer calls any theme() functions. This clears up 2 issues:
- #316108: simplemenu disappears if theme_developer module is enabled theme_developer wraps all output of theme functions in an extra span tag which causes javascript problems with superfish.js. We're no longer calling theme() functions to build the menu so this is fixed.
- #336119: Problems with administration theme displaying on block admin page This is caused by calls to theme() functions from within hook_init() which initializes the theme system prematurely. Again, no theme() functions when building the menu fixes this.
Any reviews and/or opinions welcome.
Comment #3
AlexisWilke commented- #316108: simplemenu disappears if theme_developer module is enabled: simplemenu disappears if theme_developer module is enabled. theme_developer wraps all output of theme functions in an extra span tag which causes javascript problems with superfish.js. We're no longer calling theme() functions to build the menu so this is fixed.
No, the problem is the bad theme. I'm pretty sure. Check the theme for the
print $closure;code. If you cannot see it, then the theme is broken and needs to be fixed.Comment #4
zroger commentedcommitted, to 6.x-2.x-dev.
Comment #6
simeThanks Roger!
Comment #7
ndowens04 commentedI am requesting that the menu would degrade gracefully so that if it is used as the primary menu, search engines could crawl the links
Comment #8
AlexisWilke commentedndowens04,
This issue had nothing to do with degrading or what not. If you wanted such a feature you should have posted another issue.
Also, you may want to look in the Nice Menus instead since that other menu is specially done to replace any one of your module with a drop down menu.
Thank you.
Alexis