class ToolbarMenuLinkTree in Drupal 10
Same name and namespace in other branches
- 8 core/modules/toolbar/src/Menu/ToolbarMenuLinkTree.php \Drupal\toolbar\Menu\ToolbarMenuLinkTree
- 9 core/modules/toolbar/src/Menu/ToolbarMenuLinkTree.php \Drupal\toolbar\Menu\ToolbarMenuLinkTree
Extends MenuLinkTree to add specific theme suggestions for the toolbar.
Hierarchy
- class \Drupal\Core\Menu\MenuLinkTree implements MenuLinkTreeInterface
- class \Drupal\toolbar\Menu\ToolbarMenuLinkTree
Expanded class hierarchy of ToolbarMenuLinkTree
1 string reference to 'ToolbarMenuLinkTree'
- toolbar.services.yml in core/
modules/ toolbar/ toolbar.services.yml - core/modules/toolbar/toolbar.services.yml
1 service uses ToolbarMenuLinkTree
- toolbar.menu_tree in core/
modules/ toolbar/ toolbar.services.yml - Drupal\toolbar\Menu\ToolbarMenuLinkTree
File
- core/
modules/ toolbar/ src/ Menu/ ToolbarMenuLinkTree.php, line 10
Namespace
Drupal\toolbar\MenuView source
class ToolbarMenuLinkTree extends MenuLinkTree {
/**
* {@inheritdoc}
*/
public function build(array $tree, $level = 0) {
if ($level == 0) {
if (!$tree) {
return [];
}
$build = parent::build($tree, $level);
/** @var \Drupal\Core\Menu\MenuLinkInterface $link */
$first_link = reset($tree)->link;
// Get the menu name of the first link.
$menu_name = $first_link
->getMenuName();
// Add a more specific theme suggestion to differentiate this rendered
// menu from others.
$build['#menu_name'] = $menu_name;
$build['#theme'] = 'menu__toolbar__' . strtr($menu_name, '-', '_');
return $build;
}
else {
return parent::build($tree, $level);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MenuLinkTree:: |
protected | property | The controller resolver. | |
MenuLinkTree:: |
protected | property | The active menu trail service. | |
MenuLinkTree:: |
protected | property | The menu link plugin manager. | |
MenuLinkTree:: |
protected | property | The route provider to load routes by name. | |
MenuLinkTree:: |
protected | property | The menu link tree storage. | |
MenuLinkTree:: |
protected | function | Builds the #items property for a menu tree's renderable array. | |
MenuLinkTree:: |
protected | function | Returns a tree containing of MenuLinkTreeElement based upon tree data. | |
MenuLinkTree:: |
public | function | ||
MenuLinkTree:: |
public | function | ||
MenuLinkTree:: |
public | function | ||
MenuLinkTree:: |
public | function | ||
MenuLinkTree:: |
public | function | ||
MenuLinkTree:: |
public | function | ||
MenuLinkTree:: |
public | function | Constructs a \Drupal\Core\Menu\MenuLinkTree object. | |
ToolbarMenuLinkTree:: |
public | function |
Builds a renderable array from a menu tree. Overrides MenuLinkTree:: |