You are here

protected function BookExport::exportTraverse in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/book/src/BookExport.php \Drupal\book\BookExport::exportTraverse()

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.

1 call to BookExport::exportTraverse()
BookExport::bookExportHtml in core/modules/book/src/BookExport.php
Generates HTML for export when invoked by book_export().

File

core/modules/book/src/BookExport.php, line 107
Contains \Drupal\book\BookExport.

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;
}