class BookExport (View source)

Provides methods for exporting book to different formats.

If you would like to add another format, swap this class in container.

Properties

protected EntityStorageInterface $nodeStorage

The node storage.

protected EntityViewBuilderInterface $viewBuilder

The node view builder.

protected BookManagerInterface $bookManager

The book manager.

protected EntityRepositoryInterface $entityRepository

The entity repository service.

Methods

__construct(EntityTypeManagerInterface $entity_type_manager, BookManagerInterface $book_manager, EntityRepositoryInterface $entity_repository = NULL)

Constructs a BookExport object.

array
bookExportHtml(NodeInterface $node)

Generates HTML for export when invoked by book_export().

array
exportTraverse(array $tree, callable $callable)

Traverses the book tree to build printable or exportable output.

array
bookNodeExport(NodeInterface $node, string $children = '')

Generates printer-friendly HTML for a node.

Details

__construct(EntityTypeManagerInterface $entity_type_manager, BookManagerInterface $book_manager, EntityRepositoryInterface $entity_repository = NULL)

Constructs a BookExport object.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

BookManagerInterface $book_manager

The book manager.

EntityRepositoryInterface $entity_repository

The entity repository service.

array bookExportHtml(NodeInterface $node)

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)

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

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.

Exceptions

Exception

protected array exportTraverse(array $tree, callable $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

array

The render array generated in visiting each node.

protected array bookNodeExport(NodeInterface $node, string $children = '')

Generates printer-friendly HTML for a node.

Parameters

NodeInterface $node

The node that will be output.

string $children

(optional) All the rendered child nodes within the current node. Defaults to an empty string.

Return Value

array

A render array for the exported HTML of a given node.

See also

BookExport::exportTraverse