You are here

function advanced_help_get_topic_hierarchy in Advanced Help 7

Same name and namespace in other branches
  1. 5 advanced_help.module \advanced_help_get_topic_hierarchy()
  2. 6 advanced_help.module \advanced_help_get_topic_hierarchy()

Build a hierarchy for a single module's topics.

2 calls to advanced_help_get_topic_hierarchy()
advanced_help_index_page in ./advanced_help.module
Page callback to view the advanced help topic index.
advanced_help_view_topic in ./advanced_help.module
Load and render a help topic.

File

./advanced_help.module, line 353
Pluggable system to provide advanced help facilities for Drupal and modules.

Code

function advanced_help_get_topic_hierarchy(&$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'] = array();
      }
      $topics[$parent_module][$parent]['children'][] = array(
        $module,
        $topic,
      );
      $topics[$module][$topic]['_parent'] = array(
        $parent_module,
        $parent,
      );
    }
  }
}