You are here

protected function BookManager::doBookTreeBuild in Zircon Profile 8.0

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

Builds a book tree.

This function may be used build the data for a menu tree only, for example to further massage the data manually before further processing happens. _menu_tree_check_access() needs to be invoked afterwards.

See also

menu_build_tree()

1 call to BookManager::doBookTreeBuild()
BookManager::bookTreeBuild in core/modules/book/src/BookManager.php
Builds a book tree, translates links, and checks access.

File

core/modules/book/src/BookManager.php, line 622
Contains \Drupal\book\BookManager.

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

protected function doBookTreeBuild($bid, array $parameters = array()) {

  // Static cache of already built menu trees.
  $trees =& drupal_static(__METHOD__, array());
  $language_interface = \Drupal::languageManager()
    ->getCurrentLanguage();

  // Build the cache id; sort parents to prevent duplicate storage and remove
  // default parameter values.
  if (isset($parameters['expanded'])) {
    sort($parameters['expanded']);
  }
  $tree_cid = 'book-links:' . $bid . ':tree-data:' . $language_interface
    ->getId() . ':' . hash('sha256', serialize($parameters));

  // If we do not have this tree in the static cache, check {cache_data}.
  if (!isset($trees[$tree_cid])) {
    $cache = \Drupal::cache('data')
      ->get($tree_cid);
    if ($cache && $cache->data) {
      $trees[$tree_cid] = $cache->data;
    }
  }
  if (!isset($trees[$tree_cid])) {
    $min_depth = isset($parameters['min_depth']) ? $parameters['min_depth'] : 1;
    $result = $this->bookOutlineStorage
      ->getBookMenuTree($bid, $parameters, $min_depth, static::BOOK_MAX_DEPTH);

    // Build an ordered array of links using the query result object.
    $links = array();
    foreach ($result as $link) {
      $link = (array) $link;
      $links[$link['nid']] = $link;
    }
    $active_trail = isset($parameters['active_trail']) ? $parameters['active_trail'] : array();
    $data['tree'] = $this
      ->buildBookOutlineData($links, $active_trail, $min_depth);
    $data['node_links'] = array();
    $this
      ->bookTreeCollectNodeLinks($data['tree'], $data['node_links']);

    // Cache the data, if it is not already in the cache.
    \Drupal::cache('data')
      ->set($tree_cid, $data, Cache::PERMANENT, array(
      'bid:' . $bid,
    ));
    $trees[$tree_cid] = $data;
  }
  return $trees[$tree_cid];
}