How can I get the active menu trail for the current page? If I use Drupal::menuTree() to load a menu it seems to always have inActiveTrail set to FALSE for all my items.

As an example consider the following code:

$menu_tree = Drupal::menuTree();
$parameters = new MenuTreeParameters();
$parameters-&gt;setTopLevelOnly();
$main_menu_top_level = $menu_tree-&gt;load('main', $parameters);


That code returns the top level of the main menu with inActiveTrail = FALSE for all items regardless of what page I am on.

I believe MenuTreeParameters::setActiveTrail() is meant to help here but then I have to pass in an active trail.

How do I get the active menu trail for the current page load so I can then pass it in?
MenuLinkTreeInterface::getCurrentRouteMenuTreeParameters() is what you want. To use the example above:

$menu_tree = Drupal::menuTree();
$parameters = $menu_tree-&gt;getCurrentRouteMenuTreeParameters('main');
$parameters-&gt;setTopLevelOnly();
$main_menu_top_level = $menu_tree-&gt;load('main', $parameters);


The resulting menu tree should have inActiveTrail flagged.