commit 5aabd064f71bbaa38ea70ff01c28120e3f5e863f Author: Joel Pittet Date: Wed May 27 22:44:55 2015 -0700 remove level diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php index 25359b1..a0cb290 100644 --- a/core/modules/book/src/BookManager.php +++ b/core/modules/book/src/BookManager.php @@ -501,9 +501,42 @@ public function getActiveTrailIds($bid, $link) { /** * {@inheritdoc} */ - public function build(array $tree, $level = 0) { + public function build(array $tree) { + $items = $this->buildItems($tree); + $build = []; - $items = []; + + if ($items) { + // Make sure drupal_render() does not re-order the links. + $build['#sorted'] = TRUE; + // Get the book id from the last link. + $item = end($items); + // Add the theme wrapper for outer markup. + // Allow menu-specific theme overrides. + $build['#theme'] = 'book_tree__book_toc_' . $item['link']['bid']; + $build['#items'] = $items; + // Set cache tag. + $build['#cache']['tags'][] = 'config:system.book.' . $item['link']['bid']; + } + + return $build; + } + + /** + * Builds the #items property for a book tree's renderable array. + * + * Helper function for ::build(). + * + * @param array $tree + * A data structure representing the tree.. + * + * @return array + * The value to use for the #items property of a renderable menu. + * + * @throws \DomainException + */ + protected function buildItems(array $tree) { + $items = array(); foreach ($tree as $data) { $class = ['menu-item']; @@ -541,24 +574,7 @@ public function build(array $tree, $level = 0) { $items[$data['link']['nid']] = $element; } - if (!$items) { - return []; - } - elseif ($level == 0) { - $build = []; - // Make sure drupal_render() does not re-order the links. - $build['#sorted'] = TRUE; - // Add the theme wrapper for outer markup. - // Allow menu-specific theme overrides. - $build['#theme'] = 'book_tree__book_toc_' . $data['link']['bid']; - $build['#items'] = $items; - // Set cache tag. - $build['#cache']['tags'][] = 'config:system.book.' . $data['link']['bid']; - return $build; - } - else { - return $items; - } + return $items; } /**