When a term has no sub-terms and/or no sub-nodes, it should not be rendered as <li class="collapsed"> or <li class="expanded">, but as <li class="leaf">. This currently does not happen.

Here is a code snippet from a version of taxonomy_context_menu_tree() that fixes this problem (sorry, I do not know how to work with CVS):

if ($terms) { 
    foreach ($terms as $term) {
      $params = array('title' => $term->description ? strip_tags(node_teaser($term->description)) : t('View this section'));
      $link = l($term->name, taxonomy_term_path($term), $params);  
      if (in_array($term->tid, $parents)) {
        if (count(taxonomy_get_children($term->tid, $vid)))
        {
        	$output .= '&lt;li class="expanded"&gt;' . $link . "\n";
        	$output .= taxonomy_context_menu_tree($vid, $term->tid, FALSE) ."\n";
        }
        else
        	$output .= '&lt;li class="leaf"&gt;' . $link . "\n";
        
        if (variable_get('taxonomy_context_block_node', TAXONOMY_CONTEXT_NODE_BLOCK_NONE)) {
          $output .= '&lt;ul class="menu"&gt;'. taxonomy_context_show_nodes($term->tid) ."&lt;/ul&gt;\n";
        }
        $output .= "&lt;/li&gt;\n";
      }
      else {
        $output .= (count(taxonomy_get_children($term->tid, $vid))) ?
        	'&lt;li class="collapsed"&gt;' . $link . "</li&gt;\n" :
        	'&lt;li class="leaf"&gt;' . $link . "</li&gt;\n";
      }
    }
  }

Note that the many calls to taxonomy_get_children() might bog everything down. However I couldn't find a better way because unfortunately your code is not very well documented (or hardly documented at all I should say).

Comments

Dio-1’s picture

Seems that drupal.org has messed up > and < (they displayed correctly when I previewed the issue). Just replace them with the correct characters in your imagination when reading the code.

NancyDru’s picture

Status: Active » Postponed (maintainer needs more info)

It looks to me like this is fixed in Version 2.