You are here

public function ToolbarHandler::processTree in Devel 8

Same name and namespace in other branches
  1. 8.3 src/ToolbarHandler.php \Drupal\devel\ToolbarHandler::processTree()
  2. 8.2 src/ToolbarHandler.php \Drupal\devel\ToolbarHandler::processTree()
  3. 4.x src/ToolbarHandler.php \Drupal\devel\ToolbarHandler::processTree()

Adds toolbar-specific attributes to the menu link tree.

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/ToolbarHandler.php, line 166

Class

ToolbarHandler
Toolbar integration handler.

Namespace

Drupal\devel

Code

public function processTree(array $tree) {
  $visible_items = $this->config
    ->get('toolbar_items') ?: [];
  foreach ($tree as $element) {
    $plugin_id = $element->link
      ->getPluginId();
    if (!in_array($plugin_id, $visible_items)) {

      // Add a class that allow to hide the non prioritized menu items when
      // the toolbar has horizontal orientation.
      $element->options['attributes']['class'][] = 'toolbar-horizontal-item-hidden';
    }
  }
  return $tree;
}