You are here

protected function CommentThread::getThreadValues in Comment Delete 8

Converts threaded comments into associative array of threads.

Parameters

array $tree: Associative array containing comment thread tree.

string $prefix: Prefix to be prepended to thread strings.

array $threads: Associative array of existing thread strings.

bool $first_level: Boolean indicating the first thread level.

Return value

array Associative array of comment thread strings.

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

File

src/CommentThread.php, line 104

Class

CommentThread
Service container for comment thread calculations.

Namespace

Drupal\comment_delete

Code

protected function getThreadValues(array $tree, $prefix = '', array $threads = [], $first_level = TRUE) {
  $thread = $first_level ? '01' : '00';
  uasort($tree, [
    $this,
    'sortThread',
  ]);
  foreach ($tree as $comment) {
    $string = (!empty($prefix) ? $prefix . '.' : '') . Number::intToAlphadecimal(sprintf('%02d', $thread++));
    $threads[$comment['cid']] = $string;
    if (isset($comment['children'])) {
      $children = $comment['children'];
      uasort($children, [
        $this,
        'sortThread',
      ]);
      $child_threading = $this
        ->getThreadValues($children, $string, $threads, FALSE);
      $threads += $child_threading;
    }
  }
  return $threads;
}