Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am using this great module with facet api, so by default, each of the facet select blocks are collapsed.
When a block is expanded and a facet link is clicked, the page is reloaded with the filter applied and the block is returned to it's collapsed state. It would be great if there was some way to keep the block(s) that where expanded at their expanded state on the page reload.
Is this something that would be possible?
Comments
Comment #1
adammaloneI've just come up against this issue myself. The way I'm looking into is to take the query parameters facetapi uses using arg() and then analysing that to determine which blocks should be open on page load.
I'll update further when/if I progress down this track!
Comment #2
adammaloneOk, so a quick piece of who knows how badly written code has produced the following.
1. Create a module for yourself with hook_init
2. In a JS file that is loaded either on every page load (place scripts[] = mymodule.js in mymodule.info) OR in a js file that is loaded only on the search page (drupal_add_js()) place the following
I'm sure it could be written with better code but this works for us!
Comment #3
modstore CreditAttribution: modstore commentedThanks typhonius, that gave me a good starting point. I used your code and made some changes to fit my implementation. Code here also if anyone else needs it. I changed it so $facet_ids variable should be the only place that needs changing.
and the js file
Comment #4
cavla CreditAttribution: cavla commentedHi guys,
I have tried both of your codes and it seems that i am out of luck.
I have tried many things/debugging to see what was wrong and i think it might come from the type of query we are looking for.
The following: if (!empty($query['f'])) always returns nothing as if i had no type of query: facet.
Any idea why?
PS: the module and the js are working fine if i don't have the check for the queries and the check for the query types...
Comment #5
modstore CreditAttribution: modstore commentedWhat do you get if you do a dpm on the $query variable?
If you can't sort it out, post your code and I will see if I can notice anything obvious.
Comment #6
adammaloneWhich options do you have if you output the results of drupal_get_query_parameters() ?
In both 7.x-1.x and 7.x-2.x facetapi the key is 'f' so this is quite curious.
Comment #7
cavla CreditAttribution: cavla commentedThanks for your replies.
Believe it or not but a dpm on the query returns nothing: blank message area with dpm and NULL with var_dump.
Same thing if I output the results of drupal_get_query_parameters() : it returns "array"
I am new to PHP coding tho but i did put the following in a custom module under my faceted block:
You can actually have a look: beta.restaurantsofbangkok.com/restaurants
Regarding the code of my module, it's pretty much the same as typhonius's:
and the js file:
Comment #8
cavla CreditAttribution: cavla commentedHi again,
I go it: i am using Pretty Facets Paths and this module "sanitize" the query for the url cleaning.
That is why it wasn't working. I got your codes to work now. Thanks
However, i'm still interested in using Pretty Facets Paths and i will work around it.
Any ideas how to get the queries before Pretty Facets Paths does?
Comment #9
adammaloneYou'll have to set your module weight lower so it gets executed before other modules.
See here for more information.
Comment #10
darvanenCleaning up the issue queue, please reopen if you would like this to be looked at.