class BookController

Controller routines for book routes.

Hierarchy

Expanded class hierarchy of BookController

File

drupal/core/modules/book/lib/Drupal/book/Controller/BookController.php, line 17
Contains \Drupal\book\Controller\BookController.

Namespace

Drupal\book\Controller
View source
class BookController implements ControllerInterface {

  /**
   * Book Manager Service.
   *
   * @var \Drupal\book\BookManager
   */
  protected $bookManager;

  /**
   * Injects BookManager Service.
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('book.manager'));
  }

  /**
   * Constructs a BookController object.
   */
  public function __construct(BookManager $bookManager) {
    $this->bookManager = $bookManager;
  }

  /**
   * Returns an administrative overview of all books.
   *
   * @return string
   *   A HTML-formatted string with 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) {
      $row = array(
        l($book['title'], $book['href'], $book['options']),
      );
      $links = array();
      $links['edit'] = array(
        'title' => t('Edit order and titles'),
        'href' => 'admin/structure/book/' . $book['nid'],
      );
      $row[] = array(
        'data' => array(
          '#type' => 'operations',
          '#links' => $links,
        ),
      );
      $rows[] = $row;
    }
    $table = array(
      '#theme' => 'table',
      '#header' => $headers,
      '#rows' => $rows,
      '#empty' => t('No books available.'),
    );
    return drupal_render($table);
  }

  /**
   * Prints a listing of all books.
   *
   * @return string
   *   A HTML-formatted string with the listing of all books content.
   */
  public function bookRender() {
    $book_list = array();
    foreach ($this->bookManager
      ->getAllBooks() as $book) {
      $book_list[] = l($book['title'], $book['href'], $book['options']);
    }
    $item_list = array(
      '#theme' => 'item_list',
      '#items' => $book_list,
    );
    return drupal_render($item_list);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BookController::$bookManager protected property Book Manager Service.
BookController::adminOverview public function Returns an administrative overview of all books.
BookController::bookRender public function Prints a listing of all books.
BookController::create public static function Injects BookManager Service. Overrides ControllerInterface::create
BookController::__construct public function Constructs a BookController object.