Same name in this branch
  1. 10 core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookSubtreeData()
  2. 10 core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::bookSubtreeData()
Same name and namespace in other branches
  1. 8.9.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookSubtreeData()
  2. 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookSubtreeData()

File

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

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

public function bookSubtreeData($link) {

  // Generate a cache ID (cid) specific for this $link.
  $cid = "book-links:subtree-data:{$link['nid']}";

  // Get it from cache, if available.
  if ($cache = $this->backendChainedCache
    ->get($cid)) {
    return $cache->data;
  }
  $result = $this->bookOutlineStorage
    ->getBookSubtree($link, static::BOOK_MAX_DEPTH);
  $links = [];
  foreach ($result as $item) {
    $links[] = $item;
  }
  $data['tree'] = $this
    ->buildBookOutlineData($links, [], $link['depth']);
  $data['node_links'] = [];
  $this
    ->bookTreeCollectNodeLinks($data['tree'], $data['node_links']);

  // Check access for the current user to each item in the tree.
  $this
    ->bookTreeCheckAccess($data['tree'], $data['node_links']);

  // Cache subtree data.
  $this->backendChainedCache
    ->set($cid, $data['tree'], Cache::PERMANENT, [
    'bid:' . $link['bid'],
  ]);
  return $data['tree'];
}