From f694b9c31d070a2abecb34e7124ec5a4d6aacfb1 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 29 Sep 2009 16:11:34 -0300 Subject: Using code from dynamic_taxonomy module Using code from dynamic_taxonomy module to build menu tree. --- finder_menu.module | 125 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 102 insertions(+), 23 deletions(-) (limited to 'finder_menu.module') diff --git a/finder_menu.module b/finder_menu.module index 9eb17b6..02b1edb 100644 --- a/finder_menu.module +++ b/finder_menu.module @@ -4,7 +4,7 @@ /** * Implementation of hook_block(); */ -function finder_taxonomy_block($op = 'list', $delta = 0, $edit = array()) { +function finder_menu_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': $blocks[0]['info'] = t('Finder Menu'); @@ -12,44 +12,123 @@ function finder_taxonomy_block($op = 'list', $delta = 0, $edit = array()) { return $blocks; case 'configure': - $form['finder_taxonomy_vid'] = array( - '#type' => 'radios', - '#title' => t('Select the vocabulary to list'), - '#default_value' => variable_get('finder_taxonomy_vid', 1), - '#options' => finder_taxonomy_get_vocabularies(), + $form['finder_menu'] = array( + '#type' => 'select', + '#title' => t('Select the menu to list'), + '#default_value' => variable_get('finder_menu', 'navigation:0'), + '#options' => menu_parent_options(menu_get_menus(), 0), ); return $form; case 'save': - variable_set('finder_taxonomy_vid', (int) $edit['finder_taxonomy_vid']); + variable_set('finder_menu', $edit['finder_menu']); break; case 'view': - $vid = variable_get('finder_taxonomy_vid', 1); - $tree = finder_taxonomy_get_terms($vid); - $block['content'] = theme('item_list', $tree); + $menu = explode(':', variable_get('finder_menu', 'navigation:0')); + $block['content'] = theme('finder_menu', $menu[0], $menu[1]); return $block; } } /** - * Get all vocabularies; + * Implementation of hook_theme(); */ -function finder_taxonomy_get_vocabularies() { - $result = db_query('SELECT vid, name from {vocabulary}'); - while ($item = db_fetch_object($result)) { - $items[$item->vid] = $item->name; +function finder_menu_theme() { + return array( + 'finder_menu' => array( + 'arguments' => array( + 'menu' => NULL, + 'parent' => NULL, + ), + ), + ); +} + +/** + * Generate the menu. + */ +function theme_finder_menu($menu_name, $mlid) { + $item_class = "finder-menu-menu-item"; + $sub_item_class = "finder-menu-sub-menu-item"; + + // Find menu item in the menu tree + + $menu_tree = menu_tree_all_data($menu_name); + $menu_link = menu_link_load($mlid); + + if ($mlid != 0) { + for ($i=1; $i<10; $i++) { + foreach($menu_tree as $menu_item) { + if ($menu_item["link"]['mlid'] == $mlid) { + $menu = $menu_item['below']; + break 2; + } + else { + if ($menu_item["link"]['mlid'] == $menu_link['p'.$i]) { + $menu_tree = $menu_item['below']; + break; + } + } + } + } + } + else { + $menu = $menu_tree; + } + + // Don't display anything if the selected menu has no children + + if (!$menu) { + return; } - return $items; + + // Backup active menu trail and set a new one + + $active_menu_name = menu_get_active_menu_name(); + menu_set_active_menu_name($menu_name); + + // Build table of mlid in the active trail + + foreach (menu_set_active_trail() as $value) { + if ($value['mlid']) { + $trail[] = $value['mlid']; + } + } + + // Restore active menu trail + + menu_set_active_menu_name($active_menu_name); + + // Build the menus + + $output = ''; + drupal_add_js(drupal_get_path('module', 'finder_menu') .'/finder_menu.js'); + + return $output; } -function finder_taxonomy_get_terms($vid = null) { - if ($vid != null) { - $tree = taxonomy_get_tree($vid); - foreach ($tree as $term) { - $items[$term->tid] = $term->name; +/** + * Recursively build the menu. + * + * @ingroup themeable + */ +function finder_menu_build($menu) { + + $output = ''; + return $output; + } -- cgit v1.2.3