function 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 174

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