You are here

function _taxonomy_menu_node_view in Taxonomy menu 6

Same name and namespace in other branches
  1. 5 taxonomy_menu.inc \_taxonomy_menu_node_view()

Generates the breadcumb for nodes that have a category listed as a menu

Parameters

Object. The node object:

Array. The list of all taxonomy vocabs and: terms that this node have and are also menus

1 call to _taxonomy_menu_node_view()
taxonomy_menu_nodeapi in ./taxonomy_menu.module
Implementation of hook_nodeapi().

File

./taxonomy_menu.inc, line 206
@author Jonathan Chaffer <jchaffer@structureinteractive.com> @author Bruno Massa <http://drupal.org/user/67164> taxonomy_menu.inc It Generates menu links for all taxonomy terms

Code

function _taxonomy_menu_node_view(&$node, &$vocabs) {
  foreach ($vocabs as $vid => $vocab) {
    $path = variable_get('taxonomy_menu_display_page', 'category') . '/' . $vid;
    $tree = taxonomy_get_tree($vid);
    $old_depth = -1;
    $old_path = $path;

    // Generate the entire breadcumb
    foreach ($tree as $term) {
      if ($term->depth <= $old_depth) {
        $slashes_to_remove = $old_depth - $term->depth + 1;
        for ($i = 0; $i < $slashes_to_remove; $i++) {
          $old_path = substr($old_path, 0, strrpos($old_path, "/"));
        }
      }
      $path = $old_path . '/' . $term->tid;
      $old_depth = $term->depth;
      $old_path = $path;
      if ($term->tid == $vocab[0]) {

        //create all the breadcrumb items
        $breadcrumb = array();
        $tmpterm = $term;
        $patharray = explode('/', $path);
        while ($tmpterm) {

          //create items for all the ancestors
          $breadcrumb[] = l($tmpterm->name, implode('/', $patharray));
          array_pop($patharray);
          if (isset($tmpterm->parents[0])) {
            $tmpterm = taxonomy_get_term($tmpterm->parents[0]);
          }
          else {
            unset($tmpterm);
          }

          //we're done with ancestors
        }
        $vocabulary = taxonomy_vocabulary_load($term->vid);
        $breadcrumb[] = l($vocabulary->name, implode('/', $patharray));

        //add the vocabulary item
        $breadcrumb[] = l(t('Home'), '<front>');
        drupal_set_breadcrumb(array_reverse($breadcrumb));

        // Quit after the first match.
        return;
      }
    }
  }
}