'. $txt .'
';
}
}
/**
* Implementation of hook_menu().
*/
function trail_menu_menu() {
$items['admin/settings/trail_menu'] = array(
'title' => 'Trail menu',
'description' => 'Configure trail menu block.',
'page callback' => 'drupal_get_form',
'page arguments' => array('trail_menu_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Form builder. Configure trail menu.
*
* @ingroup forms
* @see system_settings_form().
*/
function trail_menu_admin_settings() {
$menu_names = _trail_menu_get_menus();
$form['trail_menu_menu_name'] = array(
'#type' => 'radios',
'#title' => t('Choose menu'),
'#options' => $menu_names,
'#default_value' => variable_get('trail_menu_menu_name', TRAIL_MENU_DEFAULT_MENU),
'#description' => t('The selected menu structure will be displayed in the trail menu block.'),
);
return system_settings_form($form);
}
/**
* Implementation of hook_block().
*/
function trail_menu_block($op='list', $delta=0, $edit=array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Trail menu');
return $blocks;
case 'view':
$content = theme('trail_menu', _trail_menu_get_trail_menu_items());
$blocks['subject'] = t('Trail menu');
$blocks['content'] = $content;
return $blocks;
}
}
/**
* Implementation of hook_theme().
*/
function trail_menu_theme() {
return array(
'trail_menu' => array(
'arguments' => array('items' => NULL),
),
'trail_menu_item' => array(
'arguments' => array('item' => NULL, 'is_trail' => FALSE, 'extra_class' => NULL),
),
'trail_menu_item_link' => array(
'arguments' => array('item' => NULL, 'is_trail' => FALSE, 'extra_class' => NULL),
),
);
}
/**
* Theming trail menu.
*/
function theme_trail_menu($items) {
$output = '';
return $output;
}
/**
* Theming trail menu item.
*/
function theme_trail_menu_item($item, $is_trail=FALSE, $extra_class=NULL) {
$class = ($is_trail) ? 'trail' : 'submenu';
if (!empty($extra_class)) {
$class .= ' '. $extra_class;
}
return ''. theme('trail_menu_item_link', $item, $is_trail) .'';
}
/**
* Theming trail menu item link.
*/
function theme_trail_menu_item_link($item, $is_trail=FALSE, $extra_class=NULL) {
$output = '';
dsm($item);
$output .= l($item['link']['title'], $item['link']['href'], array());
return $output;
}
/**
* Delivers an array of menu items starting with trail items. In case the last
* (meaning 'active') menu item has own sub menu items, these will be added to
* the array. Trail items and child menu items can be distinguished by their
* 'in_active_trail' fields, with trail items set to 1.
* @return array
*/
function _trail_menu_get_trail_menu_items() {
$items = _trail_menu_get_trail_items();
// Add submenu items to $items. Submenu items are the 'below' items of the
// last menu trail item.
$last_item = $items[count($items) - 1];
if (is_array($last_item['below']) && $last_item['link']['in_active_trail'] == 1) {
$items = array_merge($items, $last_item['below']);
}
return $items;
}
/**
* Recursive function delivering an array of menu items from first to
* current item, together forming the current trail.
*
* @return array
*/
function _trail_menu_get_trail_items($items = NULL) {
static $trail;
if (!isset($items)) {
$trail = array();
$menu = variable_get('trail_menu_menu_name', TRAIL_MENU_DEFAULT_MENU);
$items = menu_tree_page_data($menu);
}
// add menu item if it is in menu's trail
foreach ($items AS $item) {
if ($item['link']['in_active_trail'] == 1) {
$trail[] = $item;
if (is_array($item['below'])) {
_trail_menu_get_trail_items($item['below']);
}
}
}
// If trail is still empty, no item is active. So we return first level
// of menu items instead for display
if (empty($trail)) {
$trail = $items;
}
return $trail;
}
/**
* Delivers an associative array (menu_name => title) containing all menus,
* ordered by menu title.
*
* @return array
*/
function _trail_menu_get_menus() {
$menus = array();
$result = db_query(db_rewrite_sql("SELECT menu_name, title FROM {menu_custom} ORDER BY title"));
while ($menu = db_fetch_array($result)) {
$menus[$menu['menu_name']] = $menu['title'];
}
return $menus;
}