You are here

protected function CommentThread::getThreadTree in Comment Delete 8

Creates associative array of threaded comments.

Parameters

array $comments: Flat array of entity comments.

int $pid: Parent ID used to recursively create array.

Return value

array Associative array of threaded comments.

1 call to CommentThread::getThreadTree()
CommentThread::thread in src/CommentThread.php
Re-thread comments attached to an entity.

File

src/CommentThread.php, line 75

Class

CommentThread
Service container for comment thread calculations.

Namespace

Drupal\comment_delete

Code

protected function getThreadTree(array $comments, $pid = 0) {
  $branch = [];
  foreach ($comments as $comment) {
    if ($comment['pid'] == $pid) {
      $children = $this
        ->getThreadTree($comments, $comment['cid']);
      if ($children) {
        $comment['children'] = $children;
      }
      $branch[] = $comment;
    }
  }
  return $branch;
}