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.
Having -Any- in selection-list-based filters is boring and un-usable. We need an option to automatically put the label inside all taxonomy-based selection lists. This would be a great usability enhancer.
Here is a sample function which does this for all selection lists:
/** Function for altering form below **/
function MYMODULE_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'views_exposed_form') {
foreach ($form['#info'] as $filtername => $filterdefs) {
$fieldname = substr ($filtername, strlen('filter-'));
if($form[$fieldname]['#type'] == 'select') {
// dpm ($fieldname);
$form[$fieldname]['#options']['All'] = t('All') . $form['#info'][$filtername]['label']; // overrides <All> on the dropdown
}
}
}
}
Comment | File | Size | Author |
---|---|---|---|
#6 | better_exposed_filters-override_any_label-1537074.patch | 1.57 KB | AaronBauman |
Comments
Comment #1
druvision CreditAttribution: druvision commentedComment #2
dave_______1 CreditAttribution: dave_______1 commentedGreat snippet of code, works perfectly!
Thanks
Comment #3
dwilkinson CreditAttribution: dwilkinson commentedThanks for this - super helpful for my needs. I made a slight tweak to set it up to show either the filter label, or "All" and included it as a template function:
Comment #4
Jo_ CreditAttribution: Jo_ commentedJust what I was looking for, thanks!
Comment #5
AaronBaumanI'd like to see an on-off toggle per-filter, as well as a user-supplied replacement text.
similar to the options for "reset" button.
Comment #6
AaronBaumanHere's a patch that offers an option to override the "Any" label text, per-field.
(under "more settings for X field")
Such a feature won't get into views core until drupal core figures out how to solve translation for user-text.
So, this patch includes a warning not to use this option when t10n / l10n / i18n are important.
Comment #7
mikeker CreditAttribution: mikeker commentedI like #6. Thanks! It has been committed.
Comment #9
kobb CreditAttribution: kobb commentedJust wondering if anyone else is having problems overriding a second or third "Any" label. It works great for just one.
Comment #10
mikeker CreditAttribution: mikeker commented@kobb, This remains a feature request as that's what it was when it was resolved. If there are bugs with the implementation/fix, those should be opened as new issues. Thanks.
Can you explain what you mean by "second and third" labels? Screenshots are worth a thousand words... :)
Comment #11
jamesfk CreditAttribution: jamesfk commentedI see what @mikeker means - if you have more than one taxonomy exposed filter - only the last one has the any changed with this, the others still say any.
Comment #12
jamesfk CreditAttribution: jamesfk commentedThe problem is the new logic for the output is one brace too far down at line 1334 on the current dev. Will roll a patch later today.
Comment #13
rei CreditAttribution: rei commentedI have the same problem with more than one exposed filter on the same field
the purpose is to have min and max drop down select list
field_price is integer. exposed 2 times using grouped filter.
1. field_price_value override '- Any -' to 'Min'
2. field_price_value_1 override '- Any -' to 'Max'
But only field_price_value_1 successfuly overriden to 'Max'
the first field_price_value still showing '- Any -'
Comment #14
Pere OrgaI confirm that this is a current issue in the dev version. The label is not replaced when using multiple filters. Shall I create a new issue for this?
Comment #15
zerobyte CreditAttribution: zerobyte commented@dwilkinson Thanks for that #3 solution. Exactly what I needed!
Comment #16
heddnre #1537074-13: Meaningful -Any- alternative for better exposed-filters usability, please open a new issue.
Comment #17
heddnHere's the follow-up. #2293401: Fully fix meaningful -Any- alternative for better exposed-filters usability