You are here

function uc_catalog_set_breadcrumb in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_catalog/uc_catalog.module \uc_catalog_set_breadcrumb()

Formats the breadcrumb to the current term's ancestry.

Parameters

$tid: The currently viewed catalog term's id.

$is_node: If true, include the current category page in the breadcrumb.

Return value

An array of breadcrumb links.

1 call to uc_catalog_set_breadcrumb()
theme_uc_catalog_browse in uc_catalog/uc_catalog.module
Display a formatted catalog page.

File

uc_catalog/uc_catalog.module, line 1164
Übercart Catalog module.

Code

function uc_catalog_set_breadcrumb($tid) {
  static $breadcrumbs = array();
  static $terms = array();
  if (variable_get('uc_catalog_breadcrumb', true)) {
    if (empty($breadcrumbs)) {
      if (variable_get('site_frontpage', 'node') != 'catalog') {
        $breadcrumbs[] = l(t('Home'), '');
      }
      if ($tid != 0) {
        $breadcrumbs[] = l(variable_get('uc_catalog_name', t('Catalog')), 'catalog');
      }
    }
    $parents = taxonomy_get_parents_all($tid);

    // Remove current term from the breadcrumb.
    array_shift($parents);
    $types = module_invoke_all('product_types');
    while (count($parents)) {
      $current = array_pop($parents);
      if (!in_array($current->tid, $terms)) {
        $n = 0;
        foreach ($types as $type) {
          $n += taxonomy_term_count_nodes($current->tid, $type);
        }
        $current->nodes = $n;
        $breadcrumbs[] = l($current->name . (variable_get('uc_catalog_breadcrumb_nodecount', false) && $current->nodes ? ' (' . $current->nodes . ')' : ''), uc_catalog_path($current));
        $terms[] = $current->tid;
      }
    }

    //print '<pre>'. print_r($breadcrumbs, true) .'</pre>';
    return $breadcrumbs;
  }
  else {
    return null;
  }
}