You are here

protected function BookManager::loadBooks in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::loadBooks()

Loads Books Array.

1 call to BookManager::loadBooks()
BookManager::getAllBooks in core/modules/book/src/BookManager.php
Returns an array of all books.

File

core/modules/book/src/BookManager.php, line 112

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

protected function loadBooks() {
  $this->books = [];
  $nids = $this->bookOutlineStorage
    ->getBooks();
  if ($nids) {
    $book_links = $this->bookOutlineStorage
      ->loadMultiple($nids);
    $nodes = $this->entityTypeManager
      ->getStorage('node')
      ->loadMultiple($nids);

    // @todo: Sort by weight and translated title.
    // @todo: use route name for links, not system path.
    foreach ($book_links as $link) {
      $nid = $link['nid'];
      if (isset($nodes[$nid]) && $nodes[$nid]
        ->access('view')) {
        $link['url'] = $nodes[$nid]
          ->toUrl();
        $link['title'] = $nodes[$nid]
          ->label();
        $link['type'] = $nodes[$nid]
          ->bundle();
        $this->books[$link['bid']] = $link;
      }
    }
  }
}