protected function BookManager::recurseTableOfContents in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/book/src/BookManager.php \Drupal\book\BookManager::recurseTableOfContents()
Recursively processes and formats book links for getTableOfContents().
This helper function recursively modifies the table of contents array for each item in the book tree, ignoring items in the exclude array or at a depth greater than the limit. Truncates titles over thirty characters and appends an indentation string incremented by depth.
Parameters
array $tree: The data structure of the book's outline tree. Includes hidden links.
string $indent: A string appended to each node title. Increments by '--' per depth level.
array $toc: Reference to the table of contents array. This is modified in place, so the function does not have a return value.
array $exclude: Optional array of Node ID values. Any link whose node ID is in this array will be excluded (along with its children).
int $depth_limit: Any link deeper than this value will be excluded (along with its children).
1 call to BookManager::recurseTableOfContents()
- BookManager::getTableOfContents in core/
modules/ book/ src/ BookManager.php - Returns an array of book pages in table of contents order.
File
- core/
modules/ book/ src/ BookManager.php, line 395 - Contains \Drupal\book\BookManager.
Class
- BookManager
- Defines a book manager.
Namespace
Drupal\bookCode
protected function recurseTableOfContents(array $tree, $indent, array &$toc, array $exclude, $depth_limit) {
$nids = array();
foreach ($tree as $data) {
if ($data['link']['depth'] > $depth_limit) {
// Don't iterate through any links on this level.
break;
}
if (!in_array($data['link']['nid'], $exclude)) {
$nids[] = $data['link']['nid'];
}
}
$nodes = $this->entityManager
->getStorage('node')
->loadMultiple($nids);
foreach ($tree as $data) {
$nid = $data['link']['nid'];
if (in_array($nid, $exclude)) {
continue;
}
$toc[$nid] = $indent . ' ' . Unicode::truncate($nodes[$nid]
->label(), 30, TRUE, TRUE);
if ($data['below']) {
$this
->recurseTableOfContents($data['below'], $indent . '--', $toc, $exclude, $depth_limit);
}
}
}