protected BookManager::buildItems(array $tree)
Builds the #items property for a book tree's renderable array.
Helper function for ::bookTreeOutput().
Parameters
array $tree: A data structure representing the tree.
Return value
array The value to use for the #items property of a renderable menu.
File
- core/modules/book/src/BookManager.php, line 533
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | protected function buildItems( array $tree ) { $items = []; foreach ( $tree as $data ) { $element = []; // Generally we only deal with visible links, but just in case. if (! $data [ 'link' ][ 'access' ]) { continue ; } // Set a class for the <li> tag. Since $data['below'] may contain local // tasks, only set 'expanded' to true if the link also has children within // the current book. $element [ 'is_expanded' ] = FALSE; $element [ 'is_collapsed' ] = FALSE; if ( $data [ 'link' ][ 'has_children' ] && $data [ 'below' ]) { $element [ 'is_expanded' ] = TRUE; } elseif ( $data [ 'link' ][ 'has_children' ]) { $element [ 'is_collapsed' ] = TRUE; } // Set a helper variable to indicate whether the link is in the active // trail. $element [ 'in_active_trail' ] = FALSE; if ( $data [ 'link' ][ 'in_active_trail' ]) { $element [ 'in_active_trail' ] = TRUE; } // Allow book-specific theme overrides. $element [ 'attributes' ] = new Attribute(); $element [ 'title' ] = $data [ 'link' ][ 'title' ]; $node = $this ->entityManager->getStorage( 'node' )->load( $data [ 'link' ][ 'nid' ]); $element [ 'url' ] = $node ->urlInfo(); $element [ 'localized_options' ] = ! empty ( $data [ 'link' ][ 'localized_options' ]) ? $data [ 'link' ][ 'localized_options' ] : []; $element [ 'localized_options' ][ 'set_active_class' ] = TRUE; $element [ 'below' ] = $data [ 'below' ] ? $this ->buildItems( $data [ 'below' ]) : []; $element [ 'original_link' ] = $data [ 'link' ]; // Index using the link's unique nid. $items [ $data [ 'link' ][ 'nid' ]] = $element ; } return $items ; } |
Please login to continue.