You are here

taxonomy_menu_hierarchy.module in Taxonomy menu 6.2

Enables Hierarchy path to Taxonomy Menu

File

taxonomy_menu_hierarchy/taxonomy_menu_hierarchy.module
View source
<?php

/**
 * @file
 *  Enables Hierarchy path to Taxonomy Menu
 */

/**
 * Implementation of hook_taxonomy_menu_path.
 *
 * @return array
 *  function name => Display Title
 *  a list of the path options.
 */
function taxonomy_menu_hierarchy_taxonomy_menu_path() {
  return array(
    'taxonomy_menu_hierarchy_path_hierarchy' => t('Hierarchy'),
  );
}

/**
 * Callback for hook_taxonomy_menu_path
 */
function taxonomy_menu_hierarchy_path_hierarchy($vid, $tid) {

  //setup the base path of category/vid
  $path = variable_get('taxonomy_menu_hierarchy_base_' . $vid, 'category') . '/' . $vid;

  //if tid = 0 then we are getting the vocab item path
  if ($tid == 0) {
    return $path;
  }

  //get the parents of the term
  $parents = taxonomy_get_parents_all($tid);

  //cycle through the parents and add them as an item on the menu
  if (!empty($parents)) {
    $path_tids = '';
    foreach ($parents as $parent) {
      $path_tids = '/' . $parent->tid . $path_tids;
    }
    $path .= $path_tids;
  }
  return $path;
}

/**
 * Implementation of hook_taxonomy_menu_options().
 * 
 * @return array
 *  Uses the value to set the variable taxonomy_menu_<value>_$vid
 *  $options[value]
 *   default - optional.  this is what will be used if the varialbe is not set.  if empty then FALSE is used
 *   #title - required.
 *   any other form element
 */
function taxonomy_menu_hierarchy_taxonomy_menu_options() {
  $options['hierarchy_base'] = array(
    '#title' => t('Base path for hierarchy path'),
    '#description' => t('Only used if the <em>Hierarchy path</em> type is selected.'),
    'default' => 'category',
    '#type' => 'textfield',
    '#weight' => -5,
  );
  return $options;
}

Functions

Namesort descending Description
taxonomy_menu_hierarchy_path_hierarchy Callback for hook_taxonomy_menu_path
taxonomy_menu_hierarchy_taxonomy_menu_options Implementation of hook_taxonomy_menu_options().
taxonomy_menu_hierarchy_taxonomy_menu_path Implementation of hook_taxonomy_menu_path.