class ToolbarMenuMenuLinkTreeManipulators in Toolbar Menu 8
Same name and namespace in other branches
- 8.2 src/ToolbarMenuMenuLinkTreeManipulators.php \Drupal\toolbar_menu\ToolbarMenuMenuLinkTreeManipulators
Provides a couple of menu link tree manipulators.
This class provides menu link tree manipulators to:
- add icons on each toolbar menu entries.
Hierarchy
- class \Drupal\toolbar_menu\ToolbarMenuMenuLinkTreeManipulators
Expanded class hierarchy of ToolbarMenuMenuLinkTreeManipulators
1 string reference to 'ToolbarMenuMenuLinkTreeManipulators'
1 service uses ToolbarMenuMenuLinkTreeManipulators
File
- src/
ToolbarMenuMenuLinkTreeManipulators.php, line 11
Namespace
Drupal\toolbar_menuView source
class ToolbarMenuMenuLinkTreeManipulators {
protected $toolbarMenuManager;
/**
* Construct a new ToolbarMenuMenuLinkTreeManipulators.
*
* @param \Drupal\toolbar_menu\ToolbarMenuManager $toolbar_menu_manager
* The toolbar_menu manager.
*/
public function __construct(ToolbarMenuManager $toolbar_menu_manager) {
$this->toolbarMenuManager = $toolbar_menu_manager;
}
/**
* Add icons on each toolbar menu items.
*
* @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree
* The menu link tree to manipulate.
*
* @return \Drupal\Core\Menu\MenuLinkTreeElement[]
* The manipulated menu link tree.
*/
public function addIcons(array $tree) {
foreach ($tree as $element) {
$element->options['attributes']['class'][] = 'toolbar-icon';
$element->options['attributes']['class'][] = 'toolbar-icon-link-toolbar-menu';
$element->options['attributes']['class'][] = 'toolbar-icon-link-toolbar-menu-' . $this->toolbarMenuManager
->cleanId($element->link
->getPluginId());
$element->options['attributes']['title'] = $element->link
->getTitle();
}
return $tree;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ToolbarMenuMenuLinkTreeManipulators:: |
protected | property | ||
ToolbarMenuMenuLinkTreeManipulators:: |
public | function | Add icons on each toolbar menu items. | |
ToolbarMenuMenuLinkTreeManipulators:: |
public | function | Construct a new ToolbarMenuMenuLinkTreeManipulators. |