You are here

class ToolbarMenuMenuLinkTreeManipulators in Toolbar Menu 8

Same name and namespace in other branches
  1. 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

Expanded class hierarchy of ToolbarMenuMenuLinkTreeManipulators

1 string reference to 'ToolbarMenuMenuLinkTreeManipulators'
toolbar_menu.services.yml in ./toolbar_menu.services.yml
toolbar_menu.services.yml
1 service uses ToolbarMenuMenuLinkTreeManipulators
toolbar_menu.menu_link_tree_manipulators in ./toolbar_menu.services.yml
Drupal\toolbar_menu\ToolbarMenuMenuLinkTreeManipulators

File

src/ToolbarMenuMenuLinkTreeManipulators.php, line 11

Namespace

Drupal\toolbar_menu
View 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

Namesort descending Modifiers Type Description Overrides
ToolbarMenuMenuLinkTreeManipulators::$toolbarMenuManager protected property
ToolbarMenuMenuLinkTreeManipulators::addIcons public function Add icons on each toolbar menu items.
ToolbarMenuMenuLinkTreeManipulators::__construct public function Construct a new ToolbarMenuMenuLinkTreeManipulators.