Hi!
I've created additional module for your project. Its features:

  • Set menu active trail to current node's lightest term's menu item. This really helps with navigation on site. For example, you have term "Cars" and opened one car node (which has term "Cars") and menu keeps expanded, so visitor still can view menu tree followed him to this node (but node doesn't have menu item, only term have one).
  • Node types, for which it happens, are configurable.
  • Process only if node doesn't have own menu item or always, it is also configurable.

My module doesn't depend on your module (but i wrote it depends in .info file). Do you want to include it in your project or I should create my own project?
First version is in attachment.
My module does something like menutrails does, but automatically for selected nodes.

Sorry for bad English, it's not my native language.

CommentFileSizeAuthor
taxonomy_menu_trails.tar_.gz1.2 KBdmitriy.trt

Comments

indytechcook’s picture

Status: Needs review » Needs work

Hello Dmitriy.trt, nice work!

This feature has been requested many times :) If you can formulate this as a patch (so others can also test) I think it could make a good addition.

I actually learned a few things from your code. There are a few changes to make this integrate nicely with taxonomy menu. If you place the options in taxonomy_menu_taxonomy_menu_options() then they will automatically show up on the vocab edit page. In your own module you could use hook_taxonomy_menu_options (http://drupal.org/node/380652).

Then you would need to make a few small changes to your hook_init and _taxonomy_menu_trails_set.

How does this work when a node has multiple terms?

Make sure you use taxonomy_menu_create_path to return the path created by taxonomy menu.

/**
 * Create the path for the vid/tid combination.
 *
 * @param $vid
 * @param $tid
 * @return string
 *  path
 */
function taxonomy_menu_create_path($vid, $tid) {
  //get the path function for this vocabulary
  $function = variable_get('taxonomy_menu_path_'. $vid, 'taxonomy_menu_path_default');
  //run the function
  return $function($vid, $tid);
}

Please work on this. I think it would be a great addition!

mattiasj’s picture

This would be great, I would love to test it.

cels’s picture

oh my $deity!

I've been looking for this feature long time, great addition!

dmitriy.trt’s picture

Last version of module is in comment's attachment: http://drupal.org/node/672014#comment-2425006
Changes from last version:

  • Module will "ask" Taxonomy Menu for path if Taxonomy Menu module exists.
  • Term selection logic is configurable: first/last/first with menu/last with menu.

indytechcook, thanks for help.

dmitriy.trt’s picture

Status: Needs work » Needs review

There is a separate project now: Taxonomy Menu Trails. Please, download and test it. This issue can be closed.

funkytraffic’s picture

Please implement tax menu trail in tax menu; espacially version 3!

Conditi0n’s picture

Status: Needs review » Closed (fixed)

@ #5

tim.plunkett’s picture

Status: Closed (fixed) » Needs review

This status is used exclusively by the Project issue tracking system to close "fixed" automatically after two weeks of inactivity. You should not need to set this status yourself.

tim.plunkett’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

anton-staroverov’s picture

Version: master » 7.x-1.x-dev
Status: Closed (fixed) » Active

I think feature described by issue author is very important. It can be implemented something like this:

function taxonomy_node_get_terms($node, $key = 'tid') {
  static $terms;
  if (!isset($terms[$node->vid][$key])) {
    $query = db_select('taxonomy_index', 'r');
    $t_alias = $query->join('taxonomy_term_data', 't', 'r.tid = t.tid');
    $v_alias = $query->join('taxonomy_vocabulary', 'v', 't.vid = v.vid');
    $query->fields( $t_alias );
    $query->condition("r.nid", $node->nid);
    $result = $query->execute();
    $terms[$node->vid][$key] = array();
    foreach ($result as $term) {
      $terms[$node->vid][$key][$term->$key] = $term;
    }
  }
  return $terms[$node->vid][$key];
}

function taxonomy_menu_init() {
  $item = menu_get_item();
  if ($item['page_callback'] == 'node_page_view') {
    $node = $item['page_arguments'][0];
    $terms = taxonomy_node_get_terms($node);
    $term = reset($terms);
    $item['href'] = 'taxonomy/term/' . $term->tid;
    menu_set_item(NULL, $item);
  }
}

Is it possible to add this feature to Taxonomy Menu?

johnv’s picture

Status: Active » Closed (fixed)