8.5.x BookManager.php BookManager::doBookTreeBuild($bid, array $parameters = [])
8.0.x BookManager.php BookManager::doBookTreeBuild($bid, array $parameters = array())
8.1.x BookManager.php BookManager::doBookTreeBuild($bid, array $parameters = array())
8.2.x BookManager.php BookManager::doBookTreeBuild($bid, array $parameters = array())
8.3.x BookManager.php BookManager::doBookTreeBuild($bid, array $parameters = [])
8.4.x BookManager.php BookManager::doBookTreeBuild($bid, array $parameters = [])
8.6.x BookManager.php BookManager::doBookTreeBuild($bid, array $parameters = [])

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.

Parameters

int $bid: The book ID to find links for.

array $parameters: (optional) An associative array of build parameters. Possible keys:

  • expanded: An array of parent link IDs to return only book links that are children of one of the parent link IDs in this list. If empty, the whole outline is built, unless 'only_active_trail' is TRUE.
  • active_trail: An array of node IDs, representing the currently active book link.
  • only_active_trail: Whether to only return links that are in the active trail. This option is ignored if 'expanded' is non-empty.
  • min_depth: The minimum depth of book links in the resulting tree. Defaults to 1, which is to build the whole tree for the book.
  • max_depth: The maximum depth of book links in the resulting tree.
  • conditions: An associative array of custom database select query condition key/value pairs; see \Drupal\book\BookOutlineStorage::getBookMenuTree() for the actual query.

Return value

array An array with links representing the tree structure of the book.

See also

\Drupal\book\BookOutlineStorageInterface::getBookMenuTree()

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 642

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