diff options
author | Silvio <silvio@socioambiental.org> | 2013-11-19 16:37:35 -0200 |
---|---|---|
committer | Silvio <silvio@socioambiental.org> | 2013-11-19 16:37:35 -0200 |
commit | d8d9193156a99bea26e6af6599f026abc7a1e56d (patch) | |
tree | a918a23747c3a48705db5518c33c24484b7dd454 | |
parent | 4856e27936b1403dab3252322229bad0f63a41cf (diff) | |
download | jquery_drawer-d8d9193156a99bea26e6af6599f026abc7a1e56d.tar.gz jquery_drawer-d8d9193156a99bea26e6af6599f026abc7a1e56d.tar.bz2 |
Initial code to remove empty menu items (#1333)
-rw-r--r-- | jquery_drawer.module | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/jquery_drawer.module b/jquery_drawer.module index 5f759d3..f382b66 100644 --- a/jquery_drawer.module +++ b/jquery_drawer.module @@ -70,14 +70,52 @@ function jquery_drawer_block($op = 'list', $delta = 0, $edit = array()) { case 'view': // Get all terms from a given vocabulary - $vid = variable_get('jquery_drawer', '1'); - $menu = taxonomy_node_tree_parents($vid); + $vid = variable_get('jquery_drawer', '1'); + $menu = taxonomy_node_tree_parents($vid); + + // Remove empty menus + foreach ($menu as $key => $term) { + if (jquery_drawer_check_empty($term->tid)) { + unset($menu[$key]); + } + } + $block['content'] = theme('jquery_drawer', $menu); return $block; } } /** + * Check empty menus. + */ +function jquery_drawer_check_empty($tid) { + $parents = array(); + $nodes = jquery_drawer_select_nodes(array($tid)); + $children = jquery_drawer_get_children($tid); + + while ($node = db_fetch_object($nodes)) { + $parents[] = $node; + } + + if (empty($parents) && empty($children)) { + return TRUE; + } +} + +/** + * Static version of taxonomy_select_nodes(). + */ +function jquery_drawer_select_nodes($tid) { + static $cache = array(); + + if (empty($cache[$tid])) { + $cache[$tid] = taxonomy_select_nodes(array($tid)); + } + + return $cache[$tid]; +} + +/** * Implementation of hook_menu(). */ function jquery_drawer_menu() { @@ -119,7 +157,6 @@ function jquery_drawer_theme() { * @ingroup themeable */ function theme_jquery_drawer($menu) { - $output = '<ul id="drw_tabs">'; $output .= implode((array) module_invoke_all('jquery_drawer')); @@ -189,7 +226,7 @@ function jquery_drawer_page($tid = NULL) { if (!isset($cache[$tid])) { $output = ''; - $nodes = taxonomy_select_nodes(array($tid)); + $nodes = jquery_drawer_select_nodes(array($tid)); $base = variable_get('jquery_drawer_link', 'node'); $tree = jquery_drawer_get_children($tid); $output .= '<ul id="drw_item" class="hidden">'; |