function BookManager::loadBooks

Same name in other branches
  1. 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::loadBooks()
  2. 8.9.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::loadBooks()
  3. 10 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

File

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

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.