function ForumController::build

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

Returns a renderable forum index page array.

Parameters

array $forums: A list of forums.

\Drupal\taxonomy\TermInterface $term: The taxonomy term of the forum.

array $topics: The topics of this forum.

array $parents: The parent forums in relation this forum.

array $header: Array of header cells.

Return value

array A render array.

2 calls to ForumController::build()
ForumController::forumIndex in core/modules/forum/src/Controller/ForumController.php
Returns forum index page.
ForumController::forumPage in core/modules/forum/src/Controller/ForumController.php
Returns forum page for a given forum.

File

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

Class

ForumController
Controller routines for forum routes.

Namespace

Drupal\forum\Controller

Code

protected function build($forums, TermInterface $term, $topics = [], $parents = [], $header = []) {
    $config = $this->config('forum.settings');
    $build = [
        '#theme' => 'forums',
        '#forums' => $forums,
        '#topics' => $topics,
        '#parents' => $parents,
        '#header' => $header,
        '#term' => $term,
        '#sortby' => $config->get('topics.order'),
        '#forums_per_page' => $config->get('topics.page_limit'),
    ];
    if (empty($term->forum_container->value)) {
        $build['#attached']['feed'][] = [
            'taxonomy/term/' . $term->id() . '/feed',
            'RSS - ' . $term->getName(),
        ];
    }
    $this->renderer
        ->addCacheableDependency($build, $config);
    foreach ($forums as $forum) {
        $this->renderer
            ->addCacheableDependency($build, $forum);
    }
    foreach ($topics as $topic) {
        $this->renderer
            ->addCacheableDependency($build, $topic);
    }
    foreach ($parents as $parent) {
        $this->renderer
            ->addCacheableDependency($build, $parent);
    }
    $this->renderer
        ->addCacheableDependency($build, $term);
    $is_forum = empty($term->forum_container->value);
    return [
        'action' => $is_forum ? $this->buildActionLinks($config->get('vocabulary'), $term) : [],
        'forum' => $build,
        '#cache' => [
            'tags' => Cache::mergeTags($this->nodeEntityTypeDefinition
                ->getListCacheTags(), $this->commentEntityTypeDefinition
                ->getListCacheTags()),
        ],
    ];
}

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