crumbs.forum.inc in Crumbs, the Breadcrumbs suite 7
File
plugins/crumbs.forum.inc
View source
<?php
function forum_crumbs_plugins($api) {
$api
->monoPlugin('forumTerm');
$api
->monoPlugin('forumTermName');
$api
->monoPlugin('forumThread');
$api
->monoPlugin('forumThreadCreate');
}
class forum_CrumbsMonoPlugin_forumTerm implements crumbs_MonoPlugin {
function describe($api) {
return t('Let /forum/123 be the parent path of /forum/456, if 123 is the parent of 456.');
}
function findParent__forum_x($path, $item) {
$term = $item['map'][1];
$term = is_numeric($term) ? taxonomy_term_load($term) : $term;
$parents = taxonomy_get_parents($term->tid);
$result = array();
foreach ($parents as $parent_tid => $parent_term) {
if ($parent_term->vocabulary_machine_name == $term->vocabulary_machine_name) {
return 'forum/' . $parent_tid;
}
}
return 'forum';
}
}
class forum_CrumbsMonoPlugin_forumTermName implements crumbs_MonoPlugin {
function describe($api) {
return t('Let /forum/123 be the parent path of /forum/456, if 123 is the parent of 456.');
}
function findTitle__forum_x($path, $item) {
$term = $item['map'][1];
$term = is_numeric($term) ? taxonomy_term_load($term) : $term;
if (!empty($term) && !empty($term->name)) {
return $term->name;
}
}
}
class forum_CrumbsMonoPlugin_forumThread implements crumbs_MonoPlugin {
function describe($api) {
return t('Let /forum/456 be the parent path of /node/789, if node 789 is a thread in this forum.');
}
function findParent__node_x($path, $item) {
$node = $item['map'][1];
$node = is_numeric($node) ? node_load($node) : $node;
if (!empty($node->forum_tid) && _forum_node_check_node_type($node)) {
return 'forum/' . $node->forum_tid;
}
}
}
class forum_CrumbsMonoPlugin_forumThreadCreate implements crumbs_MonoPlugin {
function describe($api) {
return t('Let /forum/456 be the parent path of /node/789, if node 789 is a thread in this forum.');
}
function findParent($path, $item) {
if (substr($path, 0, 9) === 'node/add/' && preg_match('#^node/add/([^/]+)/(\\d+)$#', $path, $m)) {
$type = $m[1];
$tid = (int) $m[2];
$field = field_info_instance('node', 'taxonomy_forums', $type);
if (is_array($field)) {
$term = taxonomy_term_load($item['original_map'][3]);
if ($term && $term->vocabulary_machine_name === 'forums') {
return 'forum/' . $term->tid;
}
}
}
}
function findTitle($path, $item) {
if (substr($path, 0, 9) === 'node/add/' && preg_match('#^node/add/([^/]+)/(\\d+)$#', $path, $m)) {
$type = $m[1];
$tid = (int) $m[2];
$field = field_info_instance('node', 'taxonomy_forums', $type);
if (is_array($field)) {
$term = taxonomy_term_load($item['original_map'][3]);
if ($term && $term->vocabulary_machine_name === 'forums') {
return $this
->newTopicTitle($type);
}
}
}
}
protected function newTopicTitle($type) {
return t('New topic');
}
}