You are here

protected function BookManager::loadBooks in Drupal 9

Same name and namespace in other branches
  1. 8 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 166

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);

    // Load nodes with proper translation.
    $nodes = $this->entityTypeManager
      ->getStorage('node')
      ->loadMultiple($nids);
    $nodes = array_map([
      $this->entityRepository,
      'getTranslationFromContext',
    ], $nodes);

    // @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;
      }
    }
  }
}