You are here

public function ToolbarMenuMenuLinkTreeManipulators::addIcons in Toolbar Menu 8

Same name and namespace in other branches
  1. 8.2 src/ToolbarMenuMenuLinkTreeManipulators.php \Drupal\toolbar_menu\ToolbarMenuMenuLinkTreeManipulators::addIcons()

Add icons on each toolbar menu items.

Parameters

\Drupal\Core\Menu\MenuLinkTreeElement[] $tree: The menu link tree to manipulate.

Return value

\Drupal\Core\Menu\MenuLinkTreeElement[] The manipulated menu link tree.

File

src/ToolbarMenuMenuLinkTreeManipulators.php, line 34

Class

ToolbarMenuMenuLinkTreeManipulators
Provides a couple of menu link tree manipulators.

Namespace

Drupal\toolbar_menu

Code

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;
}