Active page not set when Clean URL is active

I’ve been trying to get breadcrumbs and page subnavigation to work when the Clean URL module is activated.

To work, breadcrumbs and submenus need to know that the current page is the active page. However, with Clean URL, the active page is not set.

This test prints nothing:

$activePage = $nav->findActive($nav->getContainer());
if ($activePage): 
    echo $page->title();
endif;

And I can see that the class “active” is not added to any list item in any navigation menus in the site.

I can’t figure out how to fix this. Does anyone have suggestions?

I’ve been looking through module.config, pageController.php, and MvcListeners.php and I just can’t figure out where the module is overriding the active setting for the current page.

I’ve played around with setActive() but I’m not getting anywhere with that.

It doesn’t look like this module’s github issues are being worked on, so I’m hoping to figure this out myself. And hopefully with a few pointers from someone more familiar with the routes and such.

I figured this out and I’m sharing my solution here in case it’s useful for others.

In my theme’s page template (view/omeka/site/page/show.phtml), I manually set the current page as active by replacing these lines:

$nav = $site->publicNav();
$activePage = $nav->findActive($nav->getContainer());

with these:

$nav = $site->publicNav();
$container = $nav->getContainer();
$thisPage = $container->findOneBy('label', $page->title());
if($thisPage !== null):
    $thisPage->setActive(true);
endif;
$activePage = $nav->findActive($nav->getContainer());

This may not be the best solution, but it’s working for me.

1 Like

The normal Laminas “active” support in the nav uses the routing parameters to match up the current page with the nav contents and decide which is active. I’d guess that something about Clean URL makes those not match up… maybe different routes are present in the nav vs. what’s actually routing the page view?