/** * {@inheritdoc} */ public function bookSubtreeData($link) { $tree =& drupal_static(__METHOD__, array()); // 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 = array(); foreach ($result as $item) { $links[] = $item; } $data['tree'] = $this->buildBookOutlineData($links, array(), $link['depth']); $data['node_links'] = array(); $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, array('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, array('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]; }
/** * Checks if there are any books in an outline. * * @return bool * TRUE if there are books, FALSE if not. */ protected function hasBookOutlines() { return $this->bookOutlineStorage->hasBooks(); }