How can I activate a custom Menu Tree Manipulator for all menus

by Philipp Zedler   Last Updated July 17, 2017 10:07 AM

I've created a custom tree manipulator and provided it as the service mymodule.tree_manipulators:mark_deepest_level.

I can call the service and use the manipulator for a given menu in my PHP code. This works.

Now, I would like to use my tree manipulator for all menus. I thought, this should work:

function mytheme_menu_links_discovered_alter(&$links) {
  $menu_tree = \Drupal::menuTree();
  $manipulators = array(
    array('callable' => 'mymodule.tree_manipulators:mark_deepest_level'),
  $links = $menu_tree->transform($links, $manipulators);

But it has no effect at all. Am I using the wrong hook? Where is my error?

Related Questions

how to map class in service.yml file

Updated December 14, 2017 06:07 AM

Webservice endpoint with hook_services_resources()

Updated April 13, 2015 20:03 PM

HOOK_menu_alter access callback

Updated March 07, 2018 10:07 AM

Edit account menu item in user menu

Updated May 03, 2017 12:07 PM