function book_export_traverse

book_export_traverse($tree, $visit_func)

Traverses the book tree to build printable or exportable output.

During the traversal, the $visit_func() callback is applied to each node and is called recursively for each child of the node (in weight, title order).

Parameters

$tree: A subtree of the book menu hierarchy, rooted at the current page.

$visit_func: A function callback to be called upon visiting a node in the tree.

Return value

The output generated in visiting each node.

File

modules/book/book.module, line 1240
Allows users to create and organize related content in an outline.

Code

function book_export_traverse($tree, $visit_func) {
  $output = '';

  foreach ($tree as $data) {
    // Note- access checking is already performed when building the tree.
    if ($node = node_load($data['link']['nid'], FALSE)) {
      $children = '';

      if ($data['below']) {
        $children = book_export_traverse($data['below'], $visit_func);
      }

      if (function_exists($visit_func)) {
        $output .= call_user_func($visit_func, $node, $children);
      }
      else {
        // Use the default function.
        $output .= book_node_export($node, $children);
      }
    }
  }

  return $output;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!book!book.module/function/book_export_traverse/7.x