- I use a view to display a list of books.
- The view has three pages:
/books/title
,/books/date
, and/books/popularity
. - The pages are essentially the same with different sort criteria.
- The pages use a contextual filter to select books by topic based on a taxonomy.
- The contextual filter is set to use the query parameter
topic
when the filter value is not in the URL. - Each page of the view includes a Drupal menu block with the items "By Title", "By Date", and "By Popularity" and links
/books/title
,/books/date
, and/books/popularity
. - If I invoke
/books/title?topic=5
(where 5 is the tid for the "health" topic)- A list of health books is correctly displayed.
- The "By Title"
<li>
element in the menu is given theactive
andactive-trail
classes by the menuing system (which allows the use of CSS to highlight the active menu entry on-screen).
- When I'm at
/books/title?topic=5
and click the "By Date" menu entry,/books/date
is invoked, so the topic id 5 is not passed to the "By Date" view (unsurprisingly), resulting in a list of all books sorted by date instead of just health books sorted by date.
QUESTION:
How can I pass the contextual filter value (5 in this example) from one page to another via the menu? For example, if at /books/title?topic=5
I click "By Date", I want to go to /books/date?topic=5
. How can I set that up?
NOTES
- This post is similar to an earlier one where I asked how to get the value coming through the contextual filter. I solved that. There is a twig variable available, in this case, {{ arguments.field_topic_target_id }}.
- I used this twig value to rig up my own menu. But having done that, I find that I need the goodness of the Drupal menuing system, both because it makes it easy for editors to change menu items and because it handles the addition of the
active
andactive_trail
classes to the proper menu entry. - I have read and tried dozens of approaches to passing the filter value received on to another page via a menu, but none have been effective.
BONUS
Assuming this problem can be solved, I'd really like to use clean URLs. So instead of /books/title?topic=5
I want to use /books/title/5
. This works to correctly display a list of health books sorted by title, but when used, the menuing system does NOT set the active
and active_trail
classes on the active menu <li>
, which I need it to do.