protected BookManager::buildBookOutlineRecursive(&$links, $parents, $depth)
Builds the data representing a book tree.
The function is a bit complex because the rendering of a link depends on the next book link.
Parameters
array $links: A flat array of book links that are part of the book. Each array element is an associative array of information about the book link, containing the fields from the {book} table. This array must be ordered depth-first.
array $parents: An array of the node ID values that are in the path from the current page to the root of the book tree.
int $depth: The minimum depth to include in the returned book tree.
Return value
array Book tree.
File
- core/modules/book/src/BookManager.php, line 1049
Class
- BookManager
- Defines a book manager.
Namespace
Drupal\book
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | protected function buildBookOutlineRecursive(& $links , $parents , $depth ) { $tree = array (); while ( $item = array_pop ( $links )) { // We need to determine if we're on the path to root so we can later build // the correct active trail. $item [ 'in_active_trail' ] = in_array( $item [ 'nid' ], $parents ); // Add the current link to the tree. $tree [ $item [ 'nid' ]] = array ( 'link' => $item , 'below' => array (), ); // Look ahead to the next link, but leave it on the array so it's // available to other recursive function calls if we return or build a // sub-tree. $next = end ( $links ); // Check whether the next link is the first in a new sub-tree. if ( $next && $next [ 'depth' ] > $depth ) { // Recursively call buildBookOutlineRecursive to build the sub-tree. $tree [ $item [ 'nid' ]][ 'below' ] = $this ->buildBookOutlineRecursive( $links , $parents , $next [ 'depth' ]); // Fetch next link after filling the sub-tree. $next = end ( $links ); } // Determine if we should exit the loop and $request = return. if (! $next || $next [ 'depth' ] < $depth ) { break ; } } return $tree ; } |
Please login to continue.