function BookManager::bookSubtreeData
Same name in other branches
- 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookSubtreeData()
- 10 core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::bookSubtreeData()
- 10 core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookSubtreeData()
- 11.x core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::bookSubtreeData()
- 11.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookSubtreeData()
Overrides BookManagerInterface::bookSubtreeData
File
-
core/
modules/ book/ src/ BookManager.php, line 1113
Class
- BookManager
- Defines a book manager.
Namespace
Drupal\bookCode
public function bookSubtreeData($link) {
$tree =& drupal_static(__METHOD__, []);
// Generate a cache ID (cid) specific for this $link.
$cid = 'book-links:subtree-cid:' . $link['nid'];
if (!isset($tree[$cid])) {
$tree_cid_cache = \Drupal::cache('data')->get($cid);
if ($tree_cid_cache && $tree_cid_cache->data) {
// If the cache entry exists, it will just be the cid for the actual
// data. This avoids duplication of large amounts of data.
$cache = \Drupal::cache('data')->get($tree_cid_cache->data);
if ($cache && isset($cache->data)) {
$data = $cache->data;
}
}
// If the subtree data was not in the cache, $data will be NULL.
if (!isset($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']);
// Compute the real cid for book subtree data.
$tree_cid = 'book-links:subtree-data:' . hash('sha256', serialize($data));
// Cache the data, if it is not already in the cache.
if (!\Drupal::cache('data')->get($tree_cid)) {
\Drupal::cache('data')->set($tree_cid, $data, Cache::PERMANENT, [
'bid:' . $link['bid'],
]);
}
// Cache the cid of the (shared) data using the book and item-specific
// cid.
\Drupal::cache('data')->set($cid, $tree_cid, Cache::PERMANENT, [
'bid:' . $link['bid'],
]);
}
// Check access for the current user to each item in the tree.
$this->bookTreeCheckAccess($data['tree'], $data['node_links']);
$tree[$cid] = $data['tree'];
}
return $tree[$cid];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.