function BookManager::bookTreeAllData

Same name in this branch
  1. 11.x core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::bookTreeAllData()
Same name and namespace in other branches
  1. 9 core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookTreeAllData()
  2. 8.9.x core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookTreeAllData()
  3. 10 core/modules/book/src/ProxyClass/BookManager.php \Drupal\book\ProxyClass\BookManager::bookTreeAllData()
  4. 10 core/modules/book/src/BookManager.php \Drupal\book\BookManager::bookTreeAllData()
2 calls to BookManager::bookTreeAllData()
BookManager::bookTreeGetFlat in core/modules/book/src/BookManager.php
BookManager::getTableOfContents in core/modules/book/src/BookManager.php

File

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

Class

BookManager
Defines a book manager.

Namespace

Drupal\book

Code

public function bookTreeAllData($bid, $link = NULL, $max_depth = NULL) {
    // Use $nid as flag for whether the data being loaded is for the whole tree.
    $nid = $link['nid'] ?? 0;
    $langcode = $this->languageManager
        ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
        ->getId();
    // Create a cache ID for the given $nid, $link, $langcode and $max_depth.
    $cid = implode(':', [
        'book-links',
        $bid,
        $nid,
        $langcode,
        (int) $max_depth,
    ]);
    // Get it from cache, if available.
    if ($cache = $this->memoryCache
        ->get($cid)) {
        return $cache->data;
    }
    // If the tree data was not in the static cache, build $tree_parameters.
    $tree_parameters = [
        '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.
    $tree_build = $this->bookTreeBuild($bid, $tree_parameters);
    // Cache the tree build in memory.
    $this->memoryCache
        ->set($cid, $tree_build);
    return $tree_build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.