You are here

function taxonomy_menu_path_custom_path in Taxonomy menu 6.2

Callback for taxonomy_menu_path

File

taxonomy_menu_path_custom/taxonomy_menu_path_custom.module, line 56
Implementation of hook_taxonomy_menu_options().

Code

function taxonomy_menu_path_custom_path($vid, $tid) {
  $base_path = variable_get('taxonomy_menu_taxonomy_menu_path_custom_base_path_' . $vid, 'category');
  $depth = variable_get('taxonomy_menu_taxonomy_menu_path_custom_depth_' . $vid, '');

  //if tid = 0 then we are creating the vocab menu item format will be taxonomy/term/$tid+$tid+$tid....
  if ($tid == 0) {

    //get all of the terms for the vocab
    $vtids = _taxonomy_menu_get_terms($vid);
    $end = implode(' ', $vtids);
    $path = $base_path . '/' . $end;
  }
  else {
    $path = $base_path . '/' . $tid;
    if (variable_get('taxonomy_menu_display_descendants_' . $vid, FALSE)) {

      //we wait to run this instead of durning the if above

      //because we only wan to run it once.
      $terms = taxonomy_get_tree($vid, $tid);
      foreach ($terms as $term) {
        $tids[] = $term->tid;
      }
      if ($tids) {
        $end = implode(' ', $tids);
        $path .= ' ' . $end;
      }
    }
  }
  if ($depth != '') {
    $path .= '/' . $depth;
  }
  if (variable_get('taxonomy_menu_taxonomy_menu_path_custom_use_term_name_' . $vid, false)) {
    $tids = $tids ? $tids : array(
      $tid,
    );
    foreach ($tids as $tid) {
      $term = taxonomy_get_term($tid);
      $names[] = strtolower(str_replace(' ', '-', $term->name));
    }
    $path = $base_path . '/' . implode(' ', $names);
  }
  return $path;
}