Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 .= '<li class="expanded">' . $link . "\n";
$output .= taxonomy_context_menu_tree($vid, $term->tid, FALSE) ."\n";
}
else
$output .= '<li class="leaf">' . $link . "\n";
if (variable_get('taxonomy_context_block_node', TAXONOMY_CONTEXT_NODE_BLOCK_NONE)) {
$output .= '<ul class="menu">'. taxonomy_context_show_nodes($term->tid) ."</ul>\n";
}
$output .= "</li>\n";
}
else {
$output .= (count(taxonomy_get_children($term->tid, $vid))) ?
'<li class="collapsed">' . $link . "</li>\n" :
'<li class="leaf">' . $link . "</li>\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
Comment #1
Dio-1 CreditAttribution: Dio-1 commentedSeems 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.
Comment #2
NancyDruIt looks to me like this is fixed in Version 2.