The filters in views and how they are exposed to the user reacts a bit differently depending on the type of filter that is used. The type of filter that used, is controlled by defining the data to views using hook_views_data
and hook_views_data_alter
. This is a bit code heave and not always something you need to do your self as many modules including views does a lot of this for you.
Two common filters used is
views_handler_filter_in_operator
views_handler_filter_string
The two are are fundamentally different because their assumptions and requirements are very different.
The first one, is the one that you would like to use. It's used when you store a value that has a defined list of possible values. An example could be content types which is the example that @Danielle used in her post. Since nodes can't have any random value for their content type, it's possible for views to display a list of checkboxes in the Admin interface when using this filter and a select list / multiple select list for the user when it is exposed.
The second one is used when a string is stored in the database. Using nodes as an example, the title field would be a good candidate for such a filter. Since titles can be any text, it doesn't make sense to expose title selection of a node as checkboxes or select lists, instead you get some other options like you are seeing in your view. You can filter by if the string contains a word (beginning /end / somewhere), it's length etc.
If the one that did the views integration didn't bother using the in_operator
type of filter, and describe to views (by using a php function) which options are available, you will have to do it using hook_views_data_alter.
What you need to do is:
- Create a subclass of
views_handler_filter_in_operator
- Implement
get_value_options
- Tell views about your new handler.
In code it would look like this
/**
* Define my custom in_opeator
*/
class my_custom_in_operator extends views_handler_filter_in_operator {
// overwrite the get_value_options function.
function get_value_options() {
if (isset($this->value_options)) {
return;
}
$this->value_options array('option_1' => t('Option 1'), 'option_2' => t('Option 2'));
}
}
/**
* Implements hook_views_data_alter().
*/
function my_custom_views_data_alter(&$data) {
$data['entity_type']['property']['filter']['handler'] = 'my_custom_in_operator';
}
And you're done. In reality it's actually quite simple. But finding out how to do is not as views is quite complex.