protected function BookManager::loadBooks

Loads Books Array.

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

File

drupal/core/modules/book/lib/Drupal/book/BookManager.php, line 66
Contains \Drupal\book\BookManager.

Class

BookManager
Book Manager Service.

Namespace

Drupal\book

Code

protected function loadBooks() {
  $this->books = array();
  $nids = $this->database
    ->query("SELECT DISTINCT(bid) FROM {book}")
    ->fetchCol();
  if ($nids) {
    $query = $this->database
      ->select('book', 'b', array(
      'fetch' => \PDO::FETCH_ASSOC,
    ));
    $query
      ->join('menu_links', 'ml', 'b.mlid = ml.mlid');
    $query
      ->fields('b');
    $query
      ->fields('ml');
    $query
      ->condition('b.nid', $nids);
    $query
      ->orderBy('ml.weight');
    $query
      ->orderBy('ml.link_title');
    $query
      ->addTag('node_access');
    $query
      ->addMetaData('base_table', 'book');
    $book_links = $query
      ->execute();
    $nodes = $this->entityManager
      ->getStorageController('node')
      ->load($nids);
    foreach ($book_links as $link) {
      $nid = $link['nid'];
      if (isset($nodes[$nid]) && $nodes[$nid]->status) {
        $link['href'] = $link['link_path'];
        $link['options'] = unserialize($link['options']);
        $link['title'] = $nodes[$nid]
          ->label();
        $link['type'] = $nodes[$nid]
          ->bundle();
        $this->books[$link['bid']] = $link;
      }
    }
  }
}