omeka-s
omeka-s copied to clipboard
On active browse page, all other browse pages active in navigation
If there are multiple browse links in a site's navigation, landing on one will mark all browse links in the navigation as active in the public views.
Are they all exactly the same? If so there's not much we can do about it: active-ness is judged by whether the routing parameters match and multiples of the same link will always all match.
They are all 'browse' custom links using different labels and queries.
The only way I see this working is changing the Browse navigation link from a MVC page to a URI page, like this:
// Omeka\Site\Navigation\Link\Browse::toZend()
public function toZend(array $data, SiteRepresentation $site)
{
$urlHelper = $this->getViewHelperManager->get('url');
return [
'type' => UriWithQuery::class,
'uri' => $urlHelper(
'site/resource',
['site-slug' => $site->slug(), 'controller' => 'item', 'action' => 'browse'],
['query' => $data['query']],
),
];
}
This will require injecting the view helper manager in to the Browse navigation link via a factory. It will also require extending the Uri
page class with UriWithQuery
to override the isActive()
method, like this:
// Omeka\Navigation\Page\UriWithQuery
public function isActive($recursive = false)
{
$uri = $this->getRequest()->getUri();
if (! $this->active) {
if ($this->getRequest() instanceof Request) {
if ($uri->getPath() . '?' . $uri->getQuery() === $this->getUri()) {
$this->active = true;
return true;
}
}
}
return parent::isActive($recursive);
}
Note that this now appends the query string to the page's URI path, so it matches with the current URI, which makes the current navigation link active, but none others. Admittedly, this solution is a bit hacky, but, as far as I know, it's the one that has the least impact.