More tab control with a mini-module
Due to the architecture of my theme, removing $vars['title'] removes breadcrumb-navigation, title, and all tabs.
My first approach was to change the theme's output in page.tpl.php, but I did the following to really get in control of tabs:
1. override theme_primary_local_tasks():
I put a copy of the original function (from includes/menu.inc) into my theme's "template.php", and changed the calls to menu_primary_local_tasks() and menu_secondary_local_tasks() to custom functions in a custom menu-module (called 'mysitemenu', see 2.):
<?php
function mysite_menu_local_tasks() {
/*
copy of includes/menu.inc: theme_menu_local_tasks()
changed: now uses mysitemenu_primary... and _mysitemenusecondary...
*/
$output = '';
if ($primary = mysitemenu_primary_local_tasks()) {
$output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
}
if ($secondary = mysitemenu_secondary_local_tasks()) {
$output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
}
return $output;
}
?>2. create a proper custom module called "mysitemenu" and provide the required functions:
I put a copy of the original functions (from includes/menu.inc) into "mysitemenu/mysitemenu.module", these are now ready for customization.
<?php
function mysitemenu_primary_local_tasks() {
/*
created. copy of includes/menu.inc: menu_primary_local_tasks()
*/
$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) {
/*
HERE YOU MAY PROCESS EACH PRIMARY TAB INDIVIDUALLY BY IT'S ID (using if's, etc.)
*/
$output .= theme('menu_local_task', $mid, menu_in_active_trail($mid), TRUE);
}
}
return $output;
}
function mysitemenu_secondary_local_tasks() {
/*
created. copy of includes/menu.inc: menu_secondary_local_tasks()
*/
$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) {
/*
HERE YOU MAY PROCESS EACH PRIMARY TAB INDIVIDUALLY BY IT'S ID (using if's, etc.)
*/
if (menu_in_active_trail($mid) && count($local_tasks[$mid]['children']) > 1) {
foreach ($local_tasks[$mid]['children'] as $cid) {
/*
HERE YOU MAY PROCESS EACH SECONDARY TAB INDIVIDUALLY BY IT'S ID (using if's, etc.)
*/
$output .= theme('menu_local_task', $cid, menu_in_active_trail($cid), FALSE);
}
}
}
}
return $output;
}
?>NOTE 1:
The theme is now tied to the module. So to make this work you have to change theme, activate the newly created module, then switch back to your customized theme (see 1.) Otherwise - using the customized theme without the module - you will get a PHP error, as the theme cannot find the required functions. If you get the error, temporarily edit "mytheme/template.php" -> mytheme_menu_local_tasks() (see 1.) to use the original menu_primary_local_tasks() (and ...secondary...) instead of your custom functions.
NOTE2:
You have to process primary tabs in both ...primary_local_tasks() and ...secondary_local_tasks(), as ...secondary... builds it's tabs "from scratch".
NOTE3:
You may also put your custom functions into some existing module.
NOTE4:
Of course 'mysite' is just a placeholder. Use your imagination. ;-)
