You are here

public function BookManager::bookSubtreeData in Drupal 9

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

Gets the data representing a subtree of the book hierarchy.

The root of the subtree will be the link passed as a parameter, so the returned tree will contain this item and all its descendants in the menu tree.

Parameters

array $link: A fully loaded book link.

Return value

A subtree of book links in an array, in the order they should be rendered.

Overrides BookManagerInterface::bookSubtreeData

File

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

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