function hansel_forum_action_add_forum_path_get_crumbs in Hansel breadcrumbs 7
Same name and namespace in other branches
- 8 forum/hansel_forum.module \hansel_forum_action_add_forum_path_get_crumbs()
Callback for "add forum path" breadcrumb action
Parameters
array $arguments Values from the configuration form.:
Return value
array
1 string reference to 'hansel_forum_action_add_forum_path_get_crumbs'
- hansel_forum_hansel_action_types in forum/
hansel_forum.module - Implements hook_hansel_action_types().
File
- forum/
hansel_forum.module, line 28 - Hansel forum integration
Code
function hansel_forum_action_add_forum_path_get_crumbs($arguments) {
$links = array();
// Build a list of term id's to exclude from the breadcrumbs.
if (empty($arguments['inc_containers'])) {
$exclude = variable_get('forum_containers', array());
}
else {
$exclude = array();
}
if (drupal_strtolower(hansel_arg(0)) == 'forum' && is_numeric(hansel_arg(1))) {
$tid = hansel_arg(1);
// Build a cache id
$cid = "forum:t{$tid}" . (empty($arguments['inc_containers']) ? '' : 'inc_containers');
if ($data = hansel_cache_get($cid)) {
return $data;
}
if ($term = taxonomy_term_load($tid)) {
$parents = taxonomy_get_parents_all($term->tid);
foreach ($parents as $term) {
if (in_array($term->tid, $exclude)) {
continue;
}
$links[] = array(
'title' => $term->name,
'href' => 'forum/' . $term->tid,
);
}
$links = array_reverse($links);
}
hansel_cache_set($cid, $links);
}
elseif (drupal_strtolower(hansel_arg(0)) == 'node' && is_numeric(hansel_arg(1))) {
$nid = hansel_arg(1);
// Build a cache id
$cid = "forum:n{$nid}" . (empty($arguments['inc_containers']) ? '' : 'inc_containers');
if ($data = hansel_cache_get($cid)) {
return $data;
}
if ($node = node_load($nid)) {
$vid = variable_get('forum_nav_vocabulary', 0);
$terms = array();
if (isset($node->taxonomy_forums)) {
$item = isset($node->taxonomy_forums[$node->language]) ? $node->taxonomy_forums[$node->language] : $node->taxonomy_forums['und'];
foreach ($item as $term) {
if (isset($term['taxonomy_term'])) {
$terms[$term['tid']] = $term['taxonomy_term'];
}
elseif (isset($term['tid'])) {
$terms[$term['tid']] = taxonomy_term_load($term['tid']);
}
}
}
if ($term = reset($terms)) {
$link = array();
$link[$term->tid] = array(
'title' => $term->name,
'href' => 'forum/' . $term->tid,
);
$parents = taxonomy_get_parents_all($term->tid);
foreach ($parents as $parent) {
if (in_array($parent->tid, $exclude)) {
continue;
}
$link[$parent->tid] = array(
'title' => $parent->name,
'href' => 'forum/' . $parent->tid,
);
}
foreach (array_reverse($link) as $tid => $value) {
$links[$tid] = $value;
}
}
}
hansel_cache_set($cid, $links);
}
return $links;
}