[drupal-devel] Generating custom menu & sub-menu tabs
gkrishna
gkrishna at interchange.ubc.ca
Sat Feb 12 00:38:43 UTC 2005
Using drupal-4.5
Here is the custom menu list i added to the theme to get menu and sub-menu tabs (its jeremy's hacked code)
When i click M_parent, the page refreshes, not listing any sub-tabs as desired.
M_parent --> top level menu item
M_child_1 --> child of M_parent
M_child_2 --> child of M_parent
I Step through the code to see the output ...
Note: Complete code is given at the end
$output .= "\n";
$menu = array(1882);
print_r($menu);
// output was M_parent as desired
...
foreach ($menu as $mid) {
$m = menu_get_menu();
print_r($m); // all menu ids
just listing the last few lines of the menu output,....
[1883] => Array ( [title] => M_child_1 [path] => term/38 [children] => array ( ) [pid] => 1882 )
[1884] => Array ( [title] => M_child_2 [path] => term/39 [children] => array ( ) [pid] => 1882 )
[1882] => Array ( [title] => M_parent [path] => [children] => Array ( [0] => 1883 [1] => 1884 ) [pid] => 0 ) [0] => Array ( [title] => [path] => [children] => Array ( [0] => 1 [1] => 1882 ) )
// sub-menu tabs
$output .= theme('menu_local_task', $mid, 1);
// $output .= "\n";
switch ($path[0]) {
case 'M_parent':
$submenu = array(1883,1884);
print_r($submenu); // desired output : M_child_1, M_child_2 but it is not getting listed in the menu sub tabs
...
there was no output from the submenu ...
menu table entires,
mid pid path title description weight type
...
1882 0 M_parent 0 115
1883 1882 term/38 M_child_1 -2 118
1884 1882 term/39 M_child_2 8 118
I was told that someone was working on a more generic solution. Please let me know if i am going wrong somewhere
Here is the complete code that can be added to the theme's (i use
chameleon) header tab
$tabs = "";
$output .= "<ul class=\"tabs first\">\n";
//$output .= "<ul class=\"tabs primary\">\n";
$menu = array(1882);
print_r($menu);
$active = 0;
foreach ($menu as $mid) {
$m = menu_get_menu();
print_r($m);
$path = explode("/", drupal_get_path_alias($_GET['q']));
if ($path[0] == $m['items'][$mid]['path']) {
$output .= theme('menu_local_task', $mid, 1);
$active = 1;
}
else
$output .= theme('menu_local_task', $mid, 0);
};
$output .= "</ul>\n";
if ($active) {
$output .= "<ul class=\"tabs second\">\n";
$output .= theme('menu_local_task', $mid, 1);
// $output .= "<ul class=\"tabs secondary\">\n";
switch ($path[0]) {
case 'M_parent':
$submenu = array(1883,1884);
print_r($submenu);
break;
default:
$submenu = array();
}
foreach ($submenu as $mid) {
$output .= theme('menu_local_task', $mid, 0);
}
$output .= "</ul>\n";
// hack ends
} // foreach ($menu as $mid)
More information about the drupal-devel
mailing list