BookManager::bookTreeAllData

public BookManager::bookTreeAllData($bid, $link = NULL, $max_depth = NULL)

Gets the data structure representing a named menu tree.

Since this can be the full tree including hidden items, the data returned may be used for generating an an admin interface or a select.

Note: based on menu_tree_all_data().

Parameters

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

array|null $link: (optional) A fully loaded menu link, or NULL. If a link is supplied, only the path to root will be included in the returned tree - as if this link represented the current page in a visible menu.

int|null $max_depth: (optional) Maximum depth of links to retrieve. Typically useful if only one or two levels of a sub tree are needed in conjunction with a non-NULL $link, in which case $max_depth should be greater than $link['depth'].

Return value

array An tree of menu links in an array, in the order they should be rendered.

Overrides BookManagerInterface::bookTreeAllData

File

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

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

public function bookTreeAllData($bid, $link = NULL, $max_depth = NULL) {
  $tree = &drupal_static(__METHOD__, array());
  $language_interface = \Drupal::languageManager()->getCurrentLanguage();

  // Use $nid as a flag for whether the data being loaded is for the whole
  // tree.
  $nid = isset($link['nid']) ? $link['nid'] : 0;
  // Generate a cache ID (cid) specific for this $bid, $link, $language, and
  // depth.
  $cid = 'book-links:' . $bid . ':all:' . $nid . ':' . $language_interface->getId() . ':' . (int) $max_depth;

  if (!isset($tree[$cid])) {
    // If the tree data was not in the static cache, build $tree_parameters.
    $tree_parameters = array(
      'min_depth' => 1,
      'max_depth' => $max_depth,
    );
    if ($nid) {
      $active_trail = $this->getActiveTrailIds($bid, $link);
      $tree_parameters['expanded'] = $active_trail;
      $tree_parameters['active_trail'] = $active_trail;
      $tree_parameters['active_trail'][] = $nid;
    }

    // Build the tree using the parameters; the resulting tree will be cached.
    $tree[$cid] = $this->bookTreeBuild($bid, $tree_parameters);
  }

  return $tree[$cid];
}
doc_Drupal
2016-10-29 08:48:08
Comments
Leave a Comment

Please login to continue.