You are here

public function BookController::adminOverview in Drupal 10

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

Returns an administrative overview of all books.

Return value

array A render array representing the administrative page content.

1 string reference to 'BookController::adminOverview'
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 76

Class

BookController
Controller routines for book routes.

Namespace

Drupal\book\Controller

Code

public function adminOverview() {
  $rows = [];
  $headers = [
    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 = [
      Link::fromTextAndUrl($book['title'], $url),
    ];
    $links = [];
    $links['edit'] = [
      'title' => t('Edit order and titles'),
      'url' => Url::fromRoute('book.admin_edit', [
        'node' => $book['nid'],
      ]),
    ];
    $row[] = [
      'data' => [
        '#type' => 'operations',
        '#links' => $links,
      ],
    ];
    $rows[] = $row;
  }
  return [
    '#type' => 'table',
    '#header' => $headers,
    '#rows' => $rows,
    '#empty' => t('No books available.'),
  ];
}