You are here

public function BookController::bookExport in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/book/src/Controller/BookController.php \Drupal\book\Controller\BookController::bookExport()
  2. 9 core/modules/book/src/Controller/BookController.php \Drupal\book\Controller\BookController::bookExport()

Generates representations of a book page and its children.

The method delegates the generation of output to helper methods. The method name is derived by prepending 'bookExport' to the camelized form of given output type. For example, a type of 'html' results in a call to the method bookExportHtml().

Parameters

string $type: A string encoding the type of output requested. The following types are currently supported in book module:

  • html: Printer-friendly HTML.

Other types may be supported in contributed modules.

\Drupal\node\NodeInterface $node: The node to export.

Return value

array A render array representing the node and its children in the book hierarchy in a format determined by the $type parameter.

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException

1 string reference to 'BookController::bookExport'
book.routing.yml in core/modules/book/book.routing.yml
core/modules/book/book.routing.yml

File

core/modules/book/src/Controller/BookController.php, line 153

Class

BookController
Controller routines for book routes.

Namespace

Drupal\book\Controller

Code

public function bookExport($type, NodeInterface $node) {
  $method = 'bookExport' . Container::camelize($type);

  // @todo Convert the custom export functionality to serializer.
  if (!method_exists($this->bookExport, $method)) {
    $this
      ->messenger()
      ->addStatus(t('Unknown export format.'));
    throw new NotFoundHttpException();
  }
  $exported_book = $this->bookExport
    ->{$method}($node);
  return new Response($this->renderer
    ->renderRoot($exported_book));
}