function BookExport::exportTraverse
Same name in other branches
- 9 core/modules/book/src/BookExport.php \Drupal\book\BookExport::exportTraverse()
- 8.9.x core/modules/book/src/BookExport.php \Drupal\book\BookExport::exportTraverse()
- 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
array The render array 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 114
Class
- BookExport
- Provides methods for exporting book to different formats.
Namespace
Drupal\bookCode
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) {
// Access checking is already performed when building the tree.
if ($node = $this->nodeStorage
->load($data['link']['nid'])) {
$node = $this->entityRepository
->getTranslationFromContext($node);
$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.