MenuActiveTrail::getActiveTrailIds, though it works consistently for node pages on a menu, doesn't return anything for Views that appear on the menu in exactly the same way.
See this demo site which (currently) dumps the expected menu trail for a node ("Hello") but nothing for a view (the default Archive view) at the top level of a main menu.
Question: why doesn't this work, and what method should we be using to get the active trail for view pages?
I am using MenuActiveTrail::getActiveTrailIds to get the menu active trail of the current page on the main menu, as in:
use Drupal\Core\Menu\MenuActiveTrailInterface; ... $this->menuActiveTrail = $menu_active_trail; ... ... current route set in breadcrumb builder applies() function ... $trail_ids = $this->menuActiveTrail->getActiveTrailIds('main');
almost exactly as it appears in the current (8.x-1.0-beta1) Menu Breadcrumb module.
I have now noticed that
getActiveTrailIds returns an empty active trail, for all views under all conditions I'm testing (except, as I've seen so far, the Frontpage view when it is not the site home page).
As a simple test I activated the built-in Archive view on a site I've been using for a while and it returns an empty active trail (
$trail_ids = an array with a single element, an empty string), no matter where on the "Main navigation" menu it is placed. In Page Settings its "Menu item entry" is set to type "Normal menu entry" and it doesn't matter what I select as a Parent on the menu: its active trail is empty everywhere.
I must be using the wrong function to get the active trail when the current page is a view, but I can't determine how from the documentation of
getActiveTrailIds. Users are starting to pile up for the D8 version of Menu Breadcrumb, which has used this method to get the active trail since the Alpha version, so I can't understand how or why it wouldn't work for such an obvious test case.
The conditions of this problem should be easy to reproduce, since all you'd have to do is download the module, and see that the breadcrumb trail for the Archive view has no breadcrumbs (unless there's something about all my sites here that is messed up!).