3

I have a D7 site where I have several main topics, each containing subtopics. I've made a views block which is shown on each of the pages of the main topics where you have two filter options:

  • Filter on main topic
  • Filter on subtopic

The idea is that when the user enters a URL like www.mysite.com/topics/maintopic, the main topic filter radio button is set automatically to the main topic the user entered and the first sub-topic for that main topic.

So how can I do that? I tried with a contextual filter, but unless I missed something I don't see an option to preselect a radio button in an exposed filter (nor in fact to filter basing on the last part of a URL, unless it's an argument). I also tried the following code.

function MYMODULE_form_views_exposed_form_alter(&$form, &$form_state) {
  // ...
} 

I didn't see any option to alter which radio button is selected.

0

You will need to use 2 contextual filters as each one takes a different argument, for example www.mysite.com/filter1/filter2.

You're confusing the difference between exposed filters and contextual filters, and their behaviour. An exposed filter is form based. As you want a radio button, that's perfect. However, an exposed filter passes its values either via POST or GET; the only way to get these values through the URL is via the query string.

-1

You can use hook_form_alter or hook_views_pre_render and check the url with $_GET or current_path() ,it's the fast and easy way.

Or you can play with Views create entity reference Filter (entityreference_filter) add your CONTEXTUAL FILTERS after that in your view add Reference Filter in Filter Criteria.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.