Allow for custom placement of vocab ID and term ID in path

mgenovese - March 20, 2009 - 21:59
Project:Taxonomy Navigator
Version:5.x-1.3
Component:Code
Category:feature request
Priority:normal
Assigned:nestor.mata
Status:needs review
Description

I found it useful to allow for both the vocabulary ID and the term ID to be custom placed in the specified path for a block. This allows my views to be setup with both vocab and term arguments placed where I need them.

Now I can set my "base path" as follows:

/view/myview/%vid%/%tid%

If the %tid% is left off, the module reverts to it's original functionality of appending the term ID to the end.

I tweaked the source code to do accomplish this:

function taxonomy_navigator_block_content($vid) {
  $terms = taxonomy_get_tree($vid, 0, -1, 1);
  $base_path = variable_get('taxonomy_navigator_base_path_' . $vid, 'taxonomy/term/');
  $links = array();
  foreach($terms as $term) {
    $href1 = str_replace("%tid%", $term->tid, $base_path);
    $href2 = str_replace("%vid%", $vid, $href1);
    // If the taxonomy ID replacement didn't happen, just append the taxonomy ID.
    if (strcmp($base_path, $href1) == 0) {
        $href2 = $href2 . $term->tid;
    }
    $links[$term->tid] = array(
        'title' => $term->name,
        'href' => $href2,
    );
    if(taxonomy_navigator_is_term_active($vid, $term->tid)) {
      $links[$term->tid]['attributes'] = array('class' => 'active');
    }
  }
  return theme('links', $links, array('class' => 'menu'));
}

I think others would find this useful too, so please consider incorporating this into the source. Thanks!

#1

mgenovese - March 21, 2009 - 04:17

I have also modified the code to enable vocabulary terms to be pulled from existing nodes versus from the entire list of vocab terms available. This is very useful for views. For example, if my view is only showing nodes of type X, listing all the vocabulary's terms in the Taxonomy Navigator could produce many instances where clicking will produce no results. Thus, I created the option in the block config to only select terms from nodes of a certain content type. This means that the only terms to be shown will come from actual published nodes of a given content type.

This could be expanded to cover multiple content types, instead of the single selector I have implemented. However, this is good enough for the time being.

AttachmentSize
taxonomy_navigator-5.x-1.2_20MAR09.tar_.gz 8.15 KB

#2

mgenovese - March 21, 2009 - 15:01

The above attachment had a bug. Use this one instead.

AttachmentSize
taxonomy_navigator-5.x-1.2_21Mar09.tar_.gz 8.29 KB

#3

nestor.mata - September 7, 2009 - 17:29
Version:5.x-1.2» 5.x-1.3
Assigned to:Anonymous» nestor.mata
Status:active» needs review

Implemented in version 5.x-1.3.
Ready for testing.
Thanks a lot for your code

 
 

Drupal is a registered trademark of Dries Buytaert.