From d8d9193156a99bea26e6af6599f026abc7a1e56d Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 19 Nov 2013 16:37:35 -0200 Subject: Initial code to remove empty menu items (#1333) --- jquery_drawer.module | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file 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,13 +70,51 @@ 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(). */ @@ -119,7 +157,6 @@ function jquery_drawer_theme() { * @ingroup themeable */ function theme_jquery_drawer($menu) { - $output = '