<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)
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 .= '&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).

#1

Dio - March 8, 2007 - 13:53

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

NancyDru - February 26, 2009 - 17:57
Status:active» postponed (maintainer needs more info)

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

 
 

Drupal is a registered trademark of Dries Buytaert.