I wanted to theme my facet links, but found that the function drupal_html_id() generates a different 'unique' ID for every facet on page refresh. Not practical for theming purposes, since you don't want that facet to change appearance when you click on them. My solution was to just copy the basic link widget to a separate module, take this function out, and replace it with a css-safe version of the link text from the $attributes array. This will generate the same ID every time, and theming can be safely done.
The attached module will give you an extra widget choice in the facet settings: 'themeable links'. It's a quick and dirty solution, but maybe it's useful or inspiring to someone.
Similar to this issue: http://drupal.org/node/1367612
Comment | File | Size | Author |
---|---|---|---|
#10 | facetapi-make-theming-widget-links-easier-2005098-10.patch | 2.11 KB | steinmb |
| |||
#1 | facet-jumper-menu.png | 9.67 KB | Alan D. |
facetapi_themeable_links.zip | 3.42 KB | BParticle |
Comments
Comment #1
Alan D. CreditAttribution: Alan D. commentedThe following patch add's a wrapper theming function to the widget_links item list and would let users do whatever they like with the links.
i.e. This allowed us to turn the link list into a jumper menu with minimal effort.
This is kind of a duplicate of #1367612: Use renderable arrays for facetapi links but without the complete duplication of theme_item_list(), aka it doesn't add functionality, just provides the hook to integrate with the block.
Example:
Simple globally loaded JScript used.
And the theme code to activate the jumper:
Comment #2
cpliakas CreditAttribution: cpliakas commentedLooks like a pretty slick technique. I would definitely be in favor of committing this. Anyone else using this patch? Can we confirm that it won't break existing implementations? Would love to get an RTBC from a tester.
Thanks for the contribution,
Chris
Comment #3
Alan D. CreditAttribution: Alan D. commentedI guess people would need to run update.php to clear the theme registry. I used devel to flush the caches.
Comment #4
mike.davis CreditAttribution: mike.davis commentedI've used this patch to theme the links in the way that I wanted to and this works great for that.
Comment #5
Robert Castelo CreditAttribution: Robert Castelo commented+1 from me, works great and is very useful.
I've used this to display date range facets as drop down selects, and also to add field labels for improved accessibility.
Comment #6
cpliakas CreditAttribution: cpliakas commentedMarking as needs work because it fails to apply to HEAD.
Overall functionality looks great, and I have enough +1's to make me feel good about committing the change
Thanks for the contribution,
Chris
Comment #7
narkoff CreditAttribution: narkoff commentedI am using #1 to display Date Range facets in a drop down. However, I have one basic question. I have two drop downs and want the title option value of the drop down to be different for each drop down. My PHP knowledge is limited, when I change the following line in template.php, it changes the title for both drop downs:
How can I have a unique title for each drop down? Thanks!
Comment #8
Alan D. CreditAttribution: Alan D. commentedWe no longer are supporting the site that this was done for. But install Devel on your localhost, and dpm($element); This should show you things that can be used to identify the element.
Make sure you remove the dpm() before deploying the code :)
Comment #9
narkoff CreditAttribution: narkoff commented@Alan D. Thank you for the Devel guidance. I did a dpm( get_defined_vars() ); This showed me the path to the facet Title. I then changed the referenced line in #7 above from 'Choose one...' to the path $widget_build['#title']. Now each of my drop downs shows their own facet title.
Comment #10
steinmb CreditAttribution: steinmb as a volunteer commentedRe-roll of patch. Looks RTBC to me. theme_facetapi_widget_links() is called.
Comment #11
steinmb CreditAttribution: steinmb as a volunteer commented