Hello good people of Drupal !
As I think the primary link bar (is it supposed to always be a bar ?) has a very good visual impact, I want to use it to its fullest. A sure way to emphasize this is for the user to need it so s/he has more chance of noticing it. I made a solution which doesn't require to tweak the menu settings as it simply uses the Drupal's menu API.
A problem using the bar instead of a menu block is that by default that the bar item isn't selected unless the actual node is displayed and we need to have it selected while it's in a trail. Many thanks to its author, the module Menu Trails addresses this issue.
Now that the bar has an extra use, there's a problem, it doesn't show menu items extending from secondary links. A way to circumvent this would be to use a menu bloc but it would take attention off the bar as the first two levels are included in the block. So we need the menu to be contextual and start from the current second level. Here's the PHP snippet I've put in a bloc body to do just that :
//source found at http://drupal.org/node/77099#comment-215118
// get the menu items that lead to the current menu item
$active_trail =_menu_get_active_trail();
/* already verified in the Page specific visibility settings
// get the primary menus id
$pmid = variable_get('menu_primary_menu', 0);
//does the menu id of the active top-level link match it ?
if ($active_trail[0] == $pmid)
*/
//create a tree starting from level 2
echo theme('menu_tree', $active_trail[2]);
That work great but it shows up all the time. So we need to restrict it's display only when the menu reaches the second level and it has content. Setting the block Page specific visibility to "Show if the following PHP code returns TRUE" and inserting the following snippet will do the trick :
$context_menu = FALSE;
// get the menu items that lead to the current menu item
$active_trail =_menu_get_active_trail();
// Did the user reached the desired menu level
if (count($active_trail) > 3) // ignore count of menu and first 2 levels
{
// get the primary menus id
$pmid = variable_get('menu_primary_menu', 0);
// does the menu id of the active top-level link match it ?
if ($active_trail[0] == $pmid)
{
// assign base menu
$base_menu = menu_get_item($active_trail[2]);
// Filter out nontask items from the base menu
// Based on Drupal's includes/menu.inc function : menu_get_active_nontask_item
$nontask_count = 0;
foreach ($base_menu['children'] as $mid) {
$item = menu_get_item($mid);
// Verify is iterated item is not a task
if (($item['type'] & MENU_NORMAL_ITEM)) {
// unfiltered types to ignore
switch ($item['type']) {
case 4: // delete
break;
default:
$nontask_count++;
//print "<br />"; print_r($item); // display filtered content
}//switch
}//if
}//foreach
// Does the current menu have children
if ($nontask_count > 0)
{
$context_menu = TRUE;
}
}
}
return $context_menu;
I wonder how much use you'll get of this and if you think it's worth making a module out of it.
Thank you for your feedback and constructive criticism,
William