You are here

protected function Toc::buildTree in TOC API 8

Recursively builds a hierarchical array of headers.

Parameters

array &$item: A associative array for a parent header item.

array $children: An array of keys to be associative to the parent header item.

1 call to Toc::buildTree()
Toc::getTree in src/Toc.php
Returns a hierarchical array of headers.

File

src/Toc.php, line 421

Class

Toc
Defines A class that parses the header tags from an HTML document.

Namespace

Drupal\toc_api

Code

protected function buildTree(array &$item, array $children) {
  $item['below_type'] = '';
  $item['below'] = [];
  foreach ($children as $key) {
    $child_item = $this->index[$key];
    $this
      ->buildTree($child_item, $child_item['children']);
    $item['below_type'] = $child_item['type'];
    $item['below'][$key] = $child_item;
  }
}