class BookController in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/book/src/Controller/BookController.php \Drupal\book\Controller\BookController
Controller routines for book routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\book\Controller\BookController
Expanded class hierarchy of BookController
File
- core/
modules/ book/ src/ Controller/ BookController.php, line 24 - Contains \Drupal\book\Controller\BookController.
Namespace
Drupal\book\ControllerView source
class BookController extends ControllerBase {
/**
* The book manager.
*
* @var \Drupal\book\BookManagerInterface
*/
protected $bookManager;
/**
* The book export service.
*
* @var \Drupal\book\BookExport
*/
protected $bookExport;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a BookController object.
*
* @param \Drupal\book\BookManagerInterface $bookManager
* The book manager.
* @param \Drupal\book\BookExport $bookExport
* The book export service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
*/
public function __construct(BookManagerInterface $bookManager, BookExport $bookExport, RendererInterface $renderer) {
$this->bookManager = $bookManager;
$this->bookExport = $bookExport;
$this->renderer = $renderer;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('book.manager'), $container
->get('book.export'), $container
->get('renderer'));
}
/**
* Returns an administrative overview of all books.
*
* @return array
* A render array representing the administrative page content.
*
*/
public function adminOverview() {
$rows = array();
$headers = array(
t('Book'),
t('Operations'),
);
// Add any recognized books to the table list.
foreach ($this->bookManager
->getAllBooks() as $book) {
/** @var \Drupal\Core\Url $url */
$url = $book['url'];
if (isset($book['options'])) {
$url
->setOptions($book['options']);
}
$row = array(
$this
->l($book['title'], $url),
);
$links = array();
$links['edit'] = array(
'title' => t('Edit order and titles'),
'url' => Url::fromRoute('book.admin_edit', [
'node' => $book['nid'],
]),
);
$row[] = array(
'data' => array(
'#type' => 'operations',
'#links' => $links,
),
);
$rows[] = $row;
}
return array(
'#type' => 'table',
'#header' => $headers,
'#rows' => $rows,
'#empty' => t('No books available.'),
);
}
/**
* Prints a listing of all books.
*
* @return array
* A render array representing the listing of all books content.
*/
public function bookRender() {
$book_list = array();
foreach ($this->bookManager
->getAllBooks() as $book) {
$book_list[] = $this
->l($book['title'], $book['url']);
}
return array(
'#theme' => 'item_list',
'#items' => $book_list,
'#cache' => [
'tags' => \Drupal::entityManager()
->getDefinition('node')
->getListCacheTags(),
],
);
}
/**
* 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().
*
* @param 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.
* @param \Drupal\node\NodeInterface $node
* The node to export.
*
* @return 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
*/
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)) {
drupal_set_message(t('Unknown export format.'));
throw new NotFoundHttpException();
}
$exported_book = $this->bookExport
->{$method}($node);
return new Response($this->renderer
->renderRoot($exported_book));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BookController:: |
protected | property | The book export service. | |
BookController:: |
protected | property | The book manager. | |
BookController:: |
protected | property | The renderer. | |
BookController:: |
public | function | Returns an administrative overview of all books. | |
BookController:: |
public | function | Generates representations of a book page and its children. | |
BookController:: |
public | function | Prints a listing of all books. | |
BookController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
BookController:: |
public | function | Constructs a BookController object. | |
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | 1 |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 3 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 3 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Returns a redirect response object for the specified route. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |