template_preprocess_forums
- Versions
- 6 – 7
template_preprocess_forums(&$variables)
Process variables for forums.tpl.php
The $variables array contains the following arguments:
- $forums
- $topics
- $parents
- $tid
- $sortby
- $forum_per_page
See also
Code
modules/forum/forum.module, line 822
<?php
function template_preprocess_forums(&$variables) {
global $user;
$vid = variable_get('forum_nav_vocabulary', 0);
$vocabulary = taxonomy_vocabulary_load($vid);
$title = !empty($vocabulary->name) ? $vocabulary->name : '';
// Breadcrumb navigation:
$breadcrumb[] = l(t('Home'), NULL);
if ($variables['tid']) {
$breadcrumb[] = l($vocabulary->name, 'forum');
}
if ($variables['parents']) {
$variables['parents'] = array_reverse($variables['parents']);
foreach ($variables['parents'] as $p) {
if ($p->tid == $variables['tid']) {
$title = $p->name;
}
else {
$breadcrumb[] = l($p->name, 'forum/' . $p->tid);
}
}
}
drupal_set_breadcrumb($breadcrumb);
drupal_set_title($title);
if ($variables['forums_defined'] = count($variables['forums']) || count($variables['parents'])) {
// Format the "post new content" links listing.
$forum_types = array();
// Loop through all bundles for forum taxonomy vocabulary field.
$field = field_info_field('taxonomy_' . $vocabulary->machine_name);
foreach ($field['bundles']['node'] as $type) {
// Check if the current user has the 'create' permission for this node type.
if (node_access('create', $type)) {
// Fetch the "General" name of the content type;
// Push the link with title and url to the array.
$forum_types[$type] = array('title' => t('Add new @node_type', array('@node_type' => node_type_get_name($type))), 'href' => 'node/add/' . str_replace('_', '-', $type) . '/' . $variables['tid']);
}
}
if (empty($forum_types)) {
// The user is logged-in; but denied access to create any new forum content type.
if ($user->uid) {
$forum_types['disallowed'] = array('title' => t('You are not allowed to post new content in the forum.'));
}
// The user is not logged-in; and denied access to create any new forum content type.
else {
$forum_types['login'] = array('title' => t('<a href="@login">Login</a> to post new content in the forum.', array('@login' => url('user/login', array('query' => drupal_get_destination())))), 'html' => TRUE);
}
}
$variables['links'] = $forum_types;
if (!empty($variables['forums'])) {
$variables['forums'] = theme('forum_list', $variables);
}
else {
$variables['forums'] = '';
}
if ($variables['tid'] && !in_array($variables['tid'], variable_get('forum_containers', array()))) {
$variables['topics'] = theme('forum_topic_list', $variables);
drupal_add_feed(url('taxonomy/term/' . $variables['tid'] . '/0/feed'), 'RSS - ' . $title);
}
else {
$variables['topics'] = '';
}
// Provide separate template suggestions based on what's being output. Topic id is also accounted for.
// Check both variables to be safe then the inverse. Forums with topic ID's take precedence.
if ($variables['forums'] && !$variables['topics']) {
$variables['template_files'][] = 'forums-containers';
$variables['template_files'][] = 'forums-' . $variables['tid'];
$variables['template_files'][] = 'forums-containers-' . $variables['tid'];
}
elseif (!$variables['forums'] && $variables['topics']) {
$variables['template_files'][] = 'forums-topics';
$variables['template_files'][] = 'forums-' . $variables['tid'];
$variables['template_files'][] = 'forums-topics-' . $variables['tid'];
}
else {
$variables['template_files'][] = 'forums-' . $variables['tid'];
}
}
else {
drupal_set_title(t('No forums defined'), PASS_THROUGH);
$variables['links'] = array();
$variables['forums'] = '';
$variables['topics'] = '';
}
}
?>Login or register to post comments 