function forum_page

Page callback: Prints a forum listing.

Parameters

$forum_term: A tree of all forums for a given taxonomy term ID. Defaults to NULL. See the return object of forum_forum_load() for a complete definition.

Return value

A string containing HTML representing the themed forum listing.

See also

forum_menu()

1 string reference to 'forum_page'
forum_menu in drupal/core/modules/forum/forum.module
Implements hook_menu().

File

drupal/core/modules/forum/forum.pages.inc, line 20
User page callbacks for the Forum module.

Code

function forum_page($forum_term = NULL) {
  $config = config('forum.settings');
  $vocabulary = entity_load('taxonomy_vocabulary', $config
    ->get('vocabulary'));
  if (!isset($forum_term)) {

    // On the main page, display all the top-level forums.
    $forum_term = forum_forum_load(0);

    // Set the page title to forum's vocabulary name.
    drupal_set_title($vocabulary
      ->label());
  }

  // Breadcrumb navigation.
  $breadcrumb[] = l(t('Home'), NULL);
  if ($forum_term
    ->id()) {

    // Parent of all forums is the vocabulary name.
    $breadcrumb[] = l($vocabulary
      ->label(), 'forum');
  }

  // Add all parent forums to breadcrumbs.
  if ($forum_term->parents) {
    foreach (array_reverse($forum_term->parents) as $parent) {
      if ($parent
        ->id() != $forum_term
        ->id()) {
        $breadcrumb[] = l($parent
          ->label(), 'forum/' . $parent
          ->id());
      }
    }
  }
  drupal_set_breadcrumb($breadcrumb);
  if ($forum_term
    ->id() && array_search($forum_term
    ->id(), $config
    ->get('containers')) === FALSE) {

    // Add RSS feed for forums.
    drupal_add_feed('taxonomy/term/' . $forum_term
      ->id() . '/feed', 'RSS - ' . $forum_term
      ->label());
  }
  if (empty($forum_term->forums) && empty($forum_term->parents)) {

    // Root of empty forum.
    drupal_set_title(t('No forums defined'));
  }
  $forum_per_page = $config
    ->get('topics.page_limit');
  $sort_by = $config
    ->get('topics.order');
  if (empty($forum_term->container)) {
    $topics = forum_get_topics($forum_term
      ->id(), $sort_by, $forum_per_page);
  }
  else {
    $topics = '';
  }
  $build = array(
    '#theme' => 'forums',
    '#forums' => $forum_term->forums,
    '#topics' => $topics,
    '#parents' => $forum_term->parents,
    '#tid' => $forum_term
      ->id(),
    '#sortby' => $sort_by,
    '#forums_per_page' => $forum_per_page,
  );
  $build['#attached']['css'][] = drupal_get_path('module', 'forum') . '/css/forum.module.css';
  return $build;
}