aboutsummaryrefslogtreecommitdiff
path: root/finder_menu.module
diff options
context:
space:
mode:
authorSilvio <s1lv10@uol.com.br>2009-09-29 16:11:34 -0300
committerSilvio <s1lv10@uol.com.br>2009-09-29 16:11:34 -0300
commitf694b9c31d070a2abecb34e7124ec5a4d6aacfb1 (patch)
treea63050e71adc880c4c4b75fecb6c18703a6f4f6b /finder_menu.module
parentb044ccbd57c5147affc489b6b972b8fc4672d663 (diff)
downloadfinder_menu-f694b9c31d070a2abecb34e7124ec5a4d6aacfb1.tar.gz
finder_menu-f694b9c31d070a2abecb34e7124ec5a4d6aacfb1.tar.bz2
Using code from dynamic_taxonomy module
Using code from dynamic_taxonomy module to build menu tree.
Diffstat (limited to 'finder_menu.module')
-rw-r--r--finder_menu.module125
1 files changed, 102 insertions, 23 deletions
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 = '<ul style="display:inline" class="finder-menu-menu">';
+ $output = finder_menu_build($menu);
+ $output .= '</ul>';
+ 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 = '<ul>';
+
+ foreach($menu as $menu_item) {
+ $output .= '<li>';
+ $output .= $menu_item['link']['title'];
+ if ($menu_item['below'] !== FALSE) {
+ $output .= finder_menu_build($menu_item['below']);
}
- return $items;
+ $output .= '</li>';
}
- return null;
+
+ $output .= '</ul>';
+ return $output;
+
}