You are here

private function AdvancedHelpController::getTopicHierarchy in Advanced Help 8

Build a hierarchy for a single module's topics.

Parameters

array $topics:

Return value

array

2 calls to AdvancedHelpController::getTopicHierarchy()
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 94

Class

AdvancedHelpController
Class AdvancedHelpController.

Namespace

Drupal\advanced_help\Controller

Code

private function getTopicHierarchy($topics) {
  foreach ($topics as $module => $module_topics) {
    foreach ($module_topics as $topic => $info) {
      $parent_module = $module;

      // We have a blank topic that we don't want parented to itself.
      if (!$topic) {
        continue;
      }
      if (empty($info['parent'])) {
        $parent = '';
      }
      elseif (strpos($info['parent'], '%')) {
        list($parent_module, $parent) = explode('%', $info['parent']);
        if (empty($topics[$parent_module][$parent])) {

          // If it doesn't exist, top level.
          $parent = '';
        }
      }
      else {
        $parent = $info['parent'];
        if (empty($module_topics[$parent])) {

          // If it doesn't exist, top level.
          $parent = '';
        }
      }
      if (!isset($topics[$parent_module][$parent]['children'])) {
        $topics[$parent_module][$parent]['children'] = [];
      }
      $topics[$parent_module][$parent]['children'][] = [
        $module,
        $topic,
      ];
      $topics[$module][$topic]['_parent'] = [
        $parent_module,
        $parent,
      ];
    }
  }
  return $topics;
}