<li> classes are incorrectly set, resulting in irritating menu display
Dio - March 8, 2007 - 13:51
| Project: | Taxonomy context |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Jump to:
Description
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).

#1
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.
#2
It looks to me like this is fixed in Version 2.