function ForumController::forumIndex

Same name in other branches
  1. 9 core/modules/forum/src/Controller/ForumController.php \Drupal\forum\Controller\ForumController::forumIndex()
  2. 8.9.x core/modules/forum/src/Controller/ForumController.php \Drupal\forum\Controller\ForumController::forumIndex()
  3. 10 core/modules/forum/src/Controller/ForumController.php \Drupal\forum\Controller\ForumController::forumIndex()

Returns forum index page.

Return value

array A render array.

1 string reference to 'ForumController::forumIndex'
forum.routing.yml in core/modules/forum/forum.routing.yml
core/modules/forum/forum.routing.yml

File

core/modules/forum/src/Controller/ForumController.php, line 177

Class

ForumController
Controller routines for forum routes.

Namespace

Drupal\forum\Controller

Code

public function forumIndex() {
    $vocabulary = $this->vocabularyStorage
        ->load($this->config('forum.settings')
        ->get('vocabulary'));
    $index = $this->forumManager
        ->getIndex();
    $build = $this->build($index->forums, $index);
    if (empty($index->forums)) {
        // Root of empty forum.
        $build['#title'] = $this->t('No forums defined');
    }
    else {
        // Set the page title to forum's vocabulary name.
        $build['#title'] = $vocabulary->label();
        $this->renderer
            ->addCacheableDependency($build, $vocabulary);
    }
    return $build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.