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
			}
		}
	}
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

druvision’s picture

Title: Meaningful -Any- alternative for great usability » Meaningful -Any- alternative for better exposed-filters usability
dave_______1’s picture

Great snippet of code, works perfectly!
Thanks

dwilkinson’s picture

Thanks 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:

function THEMENAME_form_alter(&$form, &$form_state, $form_id) {
// Rewrite first item for exposed filters
	if ($form_id == 'views_exposed_form') {
		foreach ($form['#info'] as $filtername => $filterdefs) {
			$fieldname = substr ($filtername, strlen('filter-'));        
			if($form[$fieldname]['#type'] == 'select') {
				// If the exposed filter has a label, use it for the first item in the list. Otherwise, use 'all'.
				if (!empty($form['#info'][$filtername]['label'])) {
					$form[$fieldname]['#options']['All'] = $form['#info'][$filtername]['label'];
				} else {
					$form[$fieldname]['#options']['All'] = t('All');
				}
			}
		}
	}
}
Jo_’s picture

Just what I was looking for, thanks!

AaronBauman’s picture

I'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.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
1.57 KB

Here'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.

mikeker’s picture

Status: Needs review » Fixed

I like #6. Thanks! It has been committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

kobb’s picture

Category: feature » bug

Just wondering if anyone else is having problems overriding a second or third "Any" label. It works great for just one.

mikeker’s picture

Category: bug » feature

@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... :)

jamesfk’s picture

I 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.

jamesfk’s picture

The 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.

rei’s picture

I 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 -'

Pere Orga’s picture

I 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?

zerobyte’s picture

@dwilkinson Thanks for that #3 solution. Exactly what I needed!

heddn’s picture

heddn’s picture