Mercurial > hg > isophonics-drupal-site
annotate core/modules/toolbar/src/Menu/ToolbarMenuLinkTree.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\toolbar\Menu; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Core\Menu\MenuLinkTree; |
Chris@0 | 6 |
Chris@0 | 7 /** |
Chris@0 | 8 * Extends MenuLinkTree to add specific theme suggestions for the toolbar. |
Chris@0 | 9 */ |
Chris@0 | 10 class ToolbarMenuLinkTree extends MenuLinkTree { |
Chris@0 | 11 |
Chris@0 | 12 /** |
Chris@0 | 13 * {@inheritdoc} |
Chris@0 | 14 */ |
Chris@0 | 15 public function build(array $tree, $level = 0) { |
Chris@0 | 16 if ($level == 0) { |
Chris@0 | 17 if (!$tree) { |
Chris@0 | 18 return []; |
Chris@0 | 19 } |
Chris@0 | 20 $build = parent::build($tree, $level); |
Chris@0 | 21 |
Chris@0 | 22 /** @var \Drupal\Core\Menu\MenuLinkInterface $link */ |
Chris@0 | 23 $first_link = reset($tree)->link; |
Chris@0 | 24 // Get the menu name of the first link. |
Chris@0 | 25 $menu_name = $first_link->getMenuName(); |
Chris@0 | 26 // Add a more specific theme suggestion to differentiate this rendered |
Chris@0 | 27 // menu from others. |
Chris@0 | 28 $build['#menu_name'] = $menu_name; |
Chris@0 | 29 $build['#theme'] = 'menu__toolbar__' . strtr($menu_name, '-', '_'); |
Chris@0 | 30 return $build; |
Chris@0 | 31 } |
Chris@0 | 32 else { |
Chris@0 | 33 return parent::build($tree, $level); |
Chris@0 | 34 } |
Chris@0 | 35 } |
Chris@0 | 36 |
Chris@0 | 37 } |