ForumManager::getChildren

public ForumManager::getChildren($vid, $tid)

Utility method to fetch the child forums for a given forum.

Parameters

int $vid: The forum vocabulary ID.

int $tid: The forum ID to fetch the children for.

Return value

array Array of children.

Overrides ForumManagerInterface::getChildren

File

core/modules/forum/src/ForumManager.php, line 398

Class

ForumManager
Provides forum manager service.

Namespace

Drupal\forum

Code

public function getChildren($vid, $tid) {
  if (!empty($this->forumChildren[$tid])) {
    return $this->forumChildren[$tid];
  }
  $forums = array();
  $_forums = $this->entityManager->getStorage('taxonomy_term')->loadTree($vid, $tid, NULL, TRUE);
  foreach ($_forums as $forum) {
    // Merge in the topic and post counters.
    if (($count = $this->getForumStatistics($forum->id()))) {
      $forum->num_topics = $count->topic_count;
      $forum->num_posts = $count->topic_count + $count->comment_count;
    }
    else {
      $forum->num_topics = 0;
      $forum->num_posts = 0;
    }

    // Merge in last post details.
    $forum->last_post = $this->getLastPost($forum->id());
    $forums[$forum->id()] = $forum;
  }

  $this->forumChildren[$tid] = $forums;
  return $forums;
}
doc_Drupal
2016-10-29 09:17:10
Comments
Leave a Comment

Please login to continue.