| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Implementation of hook_help().
|
| 4 |
*/
|
| 5 |
function primary_links_help($section) {
|
| 6 |
switch ($section) {
|
| 7 |
case 'admin/modules#description':
|
| 8 |
return t('This module provides some menu APIs that can be used in a theme');
|
| 9 |
}
|
| 10 |
}
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_menu().
|
| 14 |
*/
|
| 15 |
function primary_links_menu($may_cache) {
|
| 16 |
if($may_cache) {
|
| 17 |
$items[] = array('path' =>'admin/menu/primary',
|
| 18 |
'title'=>t('Primary links'),
|
| 19 |
'callback'=>'primary_links_config',
|
| 20 |
'access'=> user_access('administer menu'),
|
| 21 |
'type'=>MENU_LOCAL_TASK);
|
| 22 |
}
|
| 23 |
return $items;
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Configuration page.
|
| 28 |
*/
|
| 29 |
function primary_links_config() {
|
| 30 |
$op = $_POST['op'];
|
| 31 |
$edit = $_POST['edit'];
|
| 32 |
$output = '';
|
| 33 |
|
| 34 |
switch ($op) {
|
| 35 |
case t('Submit'):
|
| 36 |
variable_set('menu_primary_menu', $edit['menu_primary_menu']);
|
| 37 |
drupal_set_message(t('primary menu saved'));
|
| 38 |
//no break, becuase we want to show the form again.
|
| 39 |
default:
|
| 40 |
$menu = menu_get_menu();
|
| 41 |
$header = array(t('Menu item'), t('Expanded'), array('data' => t('Operations'), 'colspan' => '3'));
|
| 42 |
$output = '';
|
| 43 |
|
| 44 |
foreach ($menu['items'][0]['children'] as $mid) {
|
| 45 |
$options[$mid] = $menu['items'][$mid]['title'];
|
| 46 |
}
|
| 47 |
if(count($options) > 1) {
|
| 48 |
$output .= form_radios(t('primary menu items'), 'menu_primary_menu', variable_get('menu_primary_menu', 0), $options, t('Choose a container for primary menu items.'), FALSE, $attributes = NULL);
|
| 49 |
$output .= form_submit(t('Submit'));
|
| 50 |
$output = form($output);
|
| 51 |
}
|
| 52 |
else {
|
| 53 |
variable_set('menu_primary_menu', 0);
|
| 54 |
drupal_set_message(t('You have only one container. The primary items are automatically set to use that container.'));
|
| 55 |
}
|
| 56 |
break;
|
| 57 |
}
|
| 58 |
|
| 59 |
print theme('page', $output);
|
| 60 |
}
|
| 61 |
|
| 62 |
|
| 63 |
/**
|
| 64 |
* Generate the horizontal menu. Often referred to as primary and secondary links.
|
| 65 |
*
|
| 66 |
* @param $pid
|
| 67 |
* The menu ID where to render from. All children of this menu item will be rendered,
|
| 68 |
* but the item itself will be omitted.
|
| 69 |
* defaults to NULL, meaning it will use the settings from menu.
|
| 70 |
* @param $start_level
|
| 71 |
* provide the number of levels under the pid you want to show your items.
|
| 72 |
* For example, if you want to show the secondary items somewhere else, you call
|
| 73 |
* theme_tabs_menu_tree with a $start_level 2.
|
| 74 |
* @param $end_level
|
| 75 |
* provide the number of levels under the pid you want to show children of your items.
|
| 76 |
* For example, if you want to show the secondary and tertiary items somewhere else, you call
|
| 77 |
* theme_tabs_menu_tree with a $start_level 2 and $end_level 3; Provide 'inf' if you want to show all items.
|
| 78 |
* If you want only onle level , say level 2, give $start_level = 1 and $end_level = 1.
|
| 79 |
* @param $show_empty
|
| 80 |
* can be 'TRUE' or 'FALSE'
|
| 81 |
* used to render an empty secondary link tab, if therre are no secondary items.
|
| 82 |
* if no empty tab is rendered, it is very difficult to design the page in a consistant
|
| 83 |
* way. Defaults to 'TRUE'
|
| 84 |
*
|
| 85 |
* @ingroup themeable
|
| 86 |
*/
|
| 87 |
|
| 88 |
function theme_tabs_menu_tree($pid = NULL, $start_level = 1, $end_level = 2, $show_empty = TRUE) {
|
| 89 |
$menu = menu_get_menu();
|
| 90 |
|
| 91 |
if (!$pid) {
|
| 92 |
//normal sitution
|
| 93 |
$pid = variable_get('menu_primary_menu', 1);
|
| 94 |
}
|
| 95 |
else {
|
| 96 |
//we are dealing with a second row of primary tabs.
|
| 97 |
static $active_level;
|
| 98 |
}
|
| 99 |
|
| 100 |
if (!$active_level) {
|
| 101 |
$active_level = 1;
|
| 102 |
}
|
| 103 |
|
| 104 |
$tabs = '';
|
| 105 |
|
| 106 |
while ($stop == FALSE) {
|
| 107 |
$stop = TRUE;
|
| 108 |
|
| 109 |
($start_level <= $active_level) ? $tabs .= "<ul class=\"tabs level-$active_level\">\n" : NULL;
|
| 110 |
//walk trough all children.
|
| 111 |
foreach ($menu['visible'][$pid]['children'] as $mid) {
|
| 112 |
if (count($menu['visible'][$mid]['children'])) {
|
| 113 |
if (menu_in_active_trail($mid)) {
|
| 114 |
$active_mid = $mid;
|
| 115 |
($end_level == 'inf' || ($active_level < $end_level)) ? $stop = FALSE : $stop = TRUE;
|
| 116 |
$style = 'expanded';
|
| 117 |
}
|
| 118 |
else {
|
| 119 |
$style = 'collapsed';
|
| 120 |
}
|
| 121 |
}
|
| 122 |
else {
|
| 123 |
$style = 'leaf';
|
| 124 |
}
|
| 125 |
if ($start_level <= $active_level) { //TODO: the $show_empty stuff must be in here.
|
| 126 |
$tabs .= "\t\t<li class=\"$style level-$active_level\">". menu_item_link($mid) ."</li>\n";
|
| 127 |
}
|
| 128 |
}
|
| 129 |
($start_level <= $active_level) ? $tabs .= "</ul>\n" : NULL;
|
| 130 |
|
| 131 |
$pid = $active_mid;
|
| 132 |
$active_level ++;
|
| 133 |
}
|
| 134 |
|
| 135 |
return $tabs;
|
| 136 |
}
|
| 137 |
?>
|