function BookExport::exportTraverse

Same name in other branches
  1. 9 core/modules/book/src/BookExport.php \Drupal\book\BookExport::exportTraverse()
  2. 10 core/modules/book/src/BookExport.php \Drupal\book\BookExport::exportTraverse()
  3. 11.x 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 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 : [
        $this,
        'bookNodeExport',
    ];
    $build = [];
    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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.