You are here

private function AdvancedHelpController::getTree in Advanced Help 8

Build a tree of advanced help topics.

Parameters

array $topics: Topics.

array $topic_ids: Topic Ids.

int $max_depth: Maximum depth for subtopics.

int $depth: Default depth for subtopics.

Return value

array Returns list of topics/subtopics.

2 calls to AdvancedHelpController::getTree()
AdvancedHelpController::moduleIndex in src/Controller/AdvancedHelpController.php
AdvancedHelpController::viewTopic in src/Controller/AdvancedHelpController.php
Load and render a help topic.

File

src/Controller/AdvancedHelpController.php, line 173

Class

AdvancedHelpController
Class AdvancedHelpController.

Namespace

Drupal\advanced_help\Controller

Code

private function getTree($topics, $topic_ids, $max_depth = -1, $depth = 0) {
  uasort($topic_ids, [
    $this,
    'helpUasort',
  ]);
  $items = [];
  foreach ($topic_ids as $info) {
    list($module, $topic) = $info;
    $item = Link::fromTextAndUrl($topics[$module][$topic]['title'], Url::fromRoute('advanced_help.help', [
      'module' => $module,
      'topic' => $topic,
    ]));
    if (!empty($topics[$module][$topic]['children']) && ($max_depth == -1 || $depth < $max_depth)) {
      $link = [
        '#theme' => 'item_list',
        '#items' => advanced_help_get_tree($topics, $topics[$module][$topic]['children'], $max_depth, $depth + 1),
      ];
      $item .= \Drupal::service('renderer')
        ->render($link, FALSE);
    }
    $items[] = $item;
  }
  return $items;
}