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?

Thank you so much for sharing your solution, @adehner! We just ran into this problem this week after installing and activating CleanURL, and I could not for the life of me figure out what was going on.

A tidbit of information to offer: this is only a problem on our default site, as set in the Global Settings for the entire Omeka S installation. We have multiple sites in the same installation, and on all the sites except the default, the Laminas isActive() function still works (in our case, templates with logic like <?php if ($page->isActive()): ?>, for example).

Thanks, it is fixed in Clean Url 3.17.11 (and many more fixes).

2 Likes