My Drupal Setup:

Drupal: 4.6.3
Taxonomy_Context.module: 4.6.0

I am using one taxonomy vocab that's set as a single hierarchy, it contains serveral parents terms each with several sub/child-terms. When adding content nodes to the site the user is to select only one term from the hierarchy of terms in my vocab. I am using the contributed module, taxonomy_context, to handle the block navigation menu and breadcrumbs of the terms and their nodes.

Desired Functionallity of Taxonomy Context's Block Nav Menu

I would like to implement a CSS Pop-Out/Drop-Down menu system to allow 1-click access to any content on my site.

Currently when using taxonomy_context's block navigation menu to view child terms of parent terms the user must click the parent term then wait for the request to be ran by the server and the page to refreshed. This is because the whole term and node hierarchy aren't being passed to the user from the start. In most cases this creates unnecessary calls back to the server and possibily extra queries to the database.

What I need is the whole term and node hierarchy to be passed to the user everytime the taxonomy_context nav menu block is built.

How a CSS Pop-Out/Drop-Down Menu Could Be Implemented

With the full term and node hierarchy passed to the user everytime the taxonomy_context nav menu block is built an unordered list containing nested unordered lists would be generated. With simple and common CSS (and javascript for IE) this set of unordered and nested unordered lists can be transformed into a CSS Pop-Out/Drop-Down menu. The nested unordered lists (containing child/sub terms and nodes) would be hidden from view until the user moused-over the parent list items (parent terms).

Needed Changes to The Taxonomy Context Module

I think I have narrowed down the function that needs to be modified in the taxonomy_context.module to generate the output I need to implement a CSS Pop-Out/Drop-Down menu:

/**
* Return the tree hierarchy of the given node, and optionally
* the nodes below the term
*/
function taxonomy_context_show_children($tid, $base = false) {
.
.
.
}

There may need to be other modifications and possibily to other functions, I am not sure yet. The thing is I am not savy in PHP and I am pretty new to Drupal, so I am asking others who know PHP and Drupal's code architecture to help me with this modification. I can handle all the CSS code needed to make the menu work how I desire, but I need the unordered and nested unordered lists of the term and node hierarchy to start with.

Any help or suggestions will help! ;)

Comments

eferraiuolo’s picture

Version: » 4.6.x-1.x-dev

Sorry my version of taxonomy_context.module is really 4.6.0

nedjo’s picture

1. I'd welcome the type of popup menu you're suggesting as an option for the module.

2. You might want to have a look how something similar is done in the jsdomenu module.

eferraiuolo’s picture

After posting this issue I tried solving this myself, and would like to point out some other issues I found and some code I modified.

I found that the original output of the block menu navigation would have some un-needed and incorrect XHTML. If a term had no nodes under it a blank set unordered list tags would still be outputted. For example...
Original Output:

<div class="menu">
  <ul>
    <li class="expanded"><a href="term1">term1</a></li>
      <ul></ul>
    <li class="collaped"><a href="term2">term2</a></li>
  </ul>
</div>

After finding the function that outputted this list, taxonomy_context_show_children, I found everytime this function is called "

    " is outputted not matter what. This function calls itself when checking for child/sub terms and will always output a "

      " before it calls and checks for nodes and "

    " after. I have re-worked the taxonomy_context_show_children module to check for child/sub terms and nodes before outputting anything.
    Modified taxonomy_context_show_children function

    function taxonomy_context_show_children($tid, $base = false) {
      static $context;
      if (!isset($context)) {
        $context = taxonomy_context_get_context();
      }
      $parents_str = "";
      $parents_obj = taxonomy_get_parents_all($context->tid);
      foreach ($parents_obj as $p) {
        $parents_str .= $p->tid . ",";
      }
      $parents = explode(",", $parents_str);
    
      $output = "<ul>\n";
      $children = taxonomy_context_term_children($tid);
      if ($children) {
        foreach ($children as $c) {
          $term = taxonomy_get_term($c);
           $params = array("title" => $term->description ? strip_tags(node_teaser($term->description)) : t("View this section"));
          if ($c == $context->tid) {
            $params["class"] = "active";
          }
          $link = l($term->name, "taxonomy/term/". $term->tid, $params);  
    
          if (in_array($c, $parents)) {
    	  $styleClass = "expanded";
    	}
    	else {
    	  $styleClass = "collapsed drop-down";
    	}
          $output .= "<li class=\"" . $styleClass . "\">" . $link . "\n";
    
    	if (taxonomy_context_term_children($c)) {
            $output .= taxonomy_context_show_children($c, false) . "\n";
    	}
    	$nodes = taxonomy_context_show_nodes($c);
    	if ($nodes) {
            $output .= "<ul>" . $nodes . "</ul>\n";
          }
    
          $output .= "</li>\n";
        }
      }
      if ($base) {
        $output .= taxonomy_context_show_nodes($tid);
      }
      $output .= "</ul>\n";
      return $output;
    }
    

    I added in a place to add styling to create Pop-out menus. The CSS needed for these menus to work is:

    .menu li.drop-down ul { display: none; }
    .menu li.drop-down:hover > ul { display: block; }
    .menu li.drop-down:hover { list-style-image: url(menu-expanded.png); }
    

    By adding the above CSS into the drupal.css (just for a temp way to make the menus work) and overwrite the taxonomy_context_show_children function with the PHP code above, I got the follow results.

    Results:
    A dynamic menu based on one of Drupal's taxonomy vocabularies will be outputted in full, all terms, nodes, child/sub terms, and child/sub nodes will be outputted as nested unordered lists. The nested lists will be hidden from view until their parent term is moused-over. If the user is currently on a node's page which is nested under terms the menu will stay expanded like how it does by default (this could be an option or changed). Also the output is valid XHTML in all taxonomy term and node configurations.

    I would like to keep working on this a refining the code, add options, and make sure it works in all cases and all browsers (the current CSS won't work for IE, a script and other css rules will need to be implemented to make the pop-out menu work with IE).

    Currently the only development I have done with Drupal is making some custom themes, but I would like to start developing modules too, and I am not sure how I start.

    nedjo’s picture

    Thanks for the useful enhancements. I've posted a patch to the drupal core based on your suggestions. I'd like to see if that's accepted, as then we could use core CSS. If not, I suppose I'll add your changes as inline CSS.

    nedjo’s picture

    I would like to start developing modules too, and I am not sure how I start.

    Improving existing modules as you're doing is a good beginning. Beyond that, there is of course the module developer's guide to refer to.

    ricabrantes’s picture

    Status: Active » Closed (fixed)

    Closed, long time without answers