function _uc_catalog_navigation in Ubercart 5
Same name and namespace in other branches
- 8.4 uc_catalog/uc_catalog.module \_uc_catalog_navigation()
- 6.2 uc_catalog/uc_catalog.module \_uc_catalog_navigation()
- 7.3 uc_catalog/uc_catalog.module \_uc_catalog_navigation()
Emulates Drupal's menu system, but based soley on the structure of "Product Catalog".
Parameters
$branch: A treeNode object. Determines if the URL points to itself, or possibly one of it's children, if present.
If the URL points to itself or one of its products, it displays its name, and expands to show its children, otherwise displays a link and a count of the products in it. If the URL points to one of it's children, it still displays a link and product count, but must still be expanded. Otherwise, it is collapsed and a link.
Return value
An array whose first element is true if the treeNode is in hierarchy of the URL path. The second element is the HTML of the list item of itself and it's children.
1 call to _uc_catalog_navigation()
- uc_catalog_block in uc_catalog/
uc_catalog.module - Displays a menu for navigating the "Product Catalog"
File
- uc_catalog/
uc_catalog.module, line 1244 - Übercart Catalog module.
Code
function _uc_catalog_navigation($branch) {
static $terms;
static $breadcrumb;
static $types;
if (empty($types)) {
$types = module_invoke_all('product_types');
}
$branch_path = uc_catalog_path($branch);
if (!isset($breadcrumb)) {
$breadcrumb = drupal_get_breadcrumb();
}
$vid = variable_get('uc_catalog_vid', 0);
if ($_GET['q'] == $branch_path) {
// The URL points to this term.
$here = true;
}
else {
$here = false;
}
if (!isset($terms)) {
$terms = taxonomy_node_get_terms_by_vocabulary(arg(1), $vid);
}
// Determine whether to expand menu item.
if (arg(0) == 'node' && array_key_exists($branch->tid, $terms)) {
$inpath = false;
foreach ($breadcrumb as $link) {
if (strpos($link, drupal_get_path_alias($branch_path)) !== false) {
$inpath = true;
}
}
}
else {
$inpath = $here;
}
$num = 0;
foreach ($types as $type) {
$num += taxonomy_term_count_nodes($branch->tid, $type);
}
// Checks to see if node counts are desired in navigation
$num_text = '';
if (variable_get('uc_catalog_block_nodecount', TRUE)) {
$num_text = ' (' . $num . ')';
}
if (!$num) {
// No nodes in category or descendants. Not in path and display nothing.
return array(
false,
'',
);
}
$expand = variable_get('uc_catalog_expand_categories', false);
$link = l($branch->name . $num_text, $branch_path);
$active_link = l($branch->name . $num_text, $branch_path, array(
'class' => 'active',
));
if ($expand || count($branch->children)) {
$lis = array();
foreach ($branch->children as $twig) {
// Expand if children are in the menu path. Capture their output.
list($child_in_path, $lis[]) = _uc_catalog_navigation($twig);
if ($child_in_path) {
$inpath = $child_in_path;
}
}
}
$output = theme("uc_catalog_item", $here, $active_link, $lis, $expand, $inpath, $link, count($branch->children));
// Tell parent category your status, and pass on output.
return array(
$inpath,
$output,
);
}