hansel_forum.module in Hansel breadcrumbs 8
Same filename and directory in other branches
Hansel forum integration
This modules provides switches and breadcrumb actions for forums.
File
forum/hansel_forum.moduleView source
<?php
/**
* @file
* Hansel forum integration
*
* This modules provides switches and breadcrumb actions for forums.
*/
/**
* Implements hook_hansel_action_types().
*/
function hansel_forum_hansel_action_types() {
return array(
'add forum path' => array(
'get crumbs' => 'hansel_forum_action_add_forum_path_get_crumbs',
'info' => 'hansel_forum_action_add_forum_path_info',
'config form' => 'hansel_forum_action_add_forum_path_config_form',
),
);
}
/**
* Callback for "add forum path" breadcrumb action
*
* @param array $arguments Values from the configuration form.
* @return array
*/
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;
}
/**
* Callback for "add forum path" action to generate the information line
*
* @param array $arguments Values from the configuration form.
* @return string
*/
function hansel_forum_action_add_forum_path_info($arguments) {
if (empty($arguments['inc_containers'])) {
return t('Add forum path not including containers');
}
else {
return t('Add forum path including containers');
}
}
/**
* Callback to generate the configuration form for the "add forum path" action
*
* @param array $arguments
* @return array
*/
function hansel_forum_action_add_forum_path_config_form($arguments) {
$form = array();
$form['inc_containers'] = array(
'#type' => 'checkbox',
'#title' => t('Include containers'),
'#options' => $options,
'#description' => t('Include the forum containers in the breadcrumbs.'),
'#default_value' => isset($arguments['inc_containers']) ? $arguments['inc_containers'] : FALSE,
);
return $form;
}
Functions
Name![]() |
Description |
---|---|
hansel_forum_action_add_forum_path_config_form | Callback to generate the configuration form for the "add forum path" action |
hansel_forum_action_add_forum_path_get_crumbs | Callback for "add forum path" breadcrumb action |
hansel_forum_action_add_forum_path_info | Callback for "add forum path" action to generate the information line |
hansel_forum_hansel_action_types | Implements hook_hansel_action_types(). |