function BookExport::bookExportHtml
Same name in other branches
- 9 core/modules/book/src/BookExport.php \Drupal\book\BookExport::bookExportHtml()
- 8.9.x core/modules/book/src/BookExport.php \Drupal\book\BookExport::bookExportHtml()
- 11.x core/modules/book/src/BookExport.php \Drupal\book\BookExport::bookExportHtml()
Generates HTML for export when invoked by book_export().
The given node is embedded to its absolute depth in a top level section. For example, a child node with depth 2 in the hierarchy is contained in (otherwise empty) <div> elements corresponding to depth 0 and depth 1. This is intended to support WYSIWYG output; for instance, level 3 sections always look like level 3 sections, no matter their depth relative to the node selected to be exported as printer-friendly HTML.
Parameters
\Drupal\node\NodeInterface $node: The node to export.
Return value
array A render array representing the HTML for a node and its children in the book hierarchy.
Throws
\Exception Thrown when the node was not attached to a book.
File
-
core/
modules/ book/ src/ BookExport.php, line 81
Class
- BookExport
- Provides methods for exporting book to different formats.
Namespace
Drupal\bookCode
public function bookExportHtml(NodeInterface $node) {
if (!isset($node->book)) {
throw new \Exception();
}
$tree = $this->bookManager
->bookSubtreeData($node->book);
$contents = $this->exportTraverse($tree, [
$this,
'bookNodeExport',
]);
$node = $this->entityRepository
->getTranslationFromContext($node);
return [
'#theme' => 'book_export_html',
'#title' => $node->label(),
'#contents' => $contents,
'#depth' => $node->book['depth'],
'#cache' => [
'tags' => $node->getEntityType()
->getListCacheTags(),
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.