BookExport::exportTraverse

protected BookExport::exportTraverse(array $tree, $callable)

Traverses the book tree to build printable or exportable output.

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

Parameters

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

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

Return value

string The output generated in visiting each node.

File

core/modules/book/src/BookExport.php, line 102

Class

BookExport
Provides methods for exporting book to different formats.

Namespace

Drupal\book

Code

protected function exportTraverse(array $tree, $callable) {
  // If there is no valid callable, use the default callback.
  $callable = !empty($callable) ? $callable : array($this, 'bookNodeExport');

  $build = array();
  foreach ($tree as $data) {
    // Note- access checking is already performed when building the tree.
    if ($node = $this->nodeStorage->load($data['link']['nid'])) {
      $children = $data['below'] ? $this->exportTraverse($data['below'], $callable) : '';
      $build[] = call_user_func($callable, $node, $children);
    }
  }

  return $build;
}
doc_Drupal
2016-10-29 08:48:05
Comments
Leave a Comment

Please login to continue.