How can I provided simplified custom exposed filter options for a field in Views? On my site, users can input their nationality in a field provided by the Countries module.  About half the users on my site are Japanese, and the other half come from all other countries.

I have a view that allows members to search for each other, and I want to make the nationality an exposed filter.  Since there are 200+ countries in the world, I do not want to expose the entire list of countries (this would be a selection nightmare on mobile phones).

Instead, I would like to provide a select list with three options: All countries, Japan, and Not Japan.

The Views UI allows administrators to select options on select lists and limit the list to the selected options by checking a box.  This is not what I want to do, because there is no way to create a Not Japan option (which should show all members from all countries except Japan).

This answer suggests writing a custom views filter handler, but I'm a bit confused about where to begin.

The Countries module provides its own custom handlers, but (I think) these are overkill for what I need (you have to add a relationship to the country, which allows you to filter by continent, etc.); I simply need to make a version of the basic select list handler with my three options.

It seems that most views handlers extend another.  In the views/handlers folder there is a file, views_handler_filter_string.inc, which I think I can use, but I'm not really sure what the next step is to take.
I've done something very similar to that with the following process:


Implement hook_views_api() in a custom module

function MYMODULE_views_api() {
  return array(
    'api' =&gt; 3,
    'path' =&gt; drupal_get_path('module', 'MYMODULE') . '/includes/views',
  );
}

Create includes/views/views_handler_filter_MYMODULE_country.inc somewhere with code similar to this (the MYMODULE bit isn't necessary, just a bit of low-tech namespacing):

class views_handler_filter_MYMODULE_country extends views_handler_filter_in_operator {

  /**
  * Get value options for the select list.
  */
  function get_value_options() {
    // Replace $this-&gt;value_options with an appropriately filtered list.
    $this-&gt;value_options = function_to_build_filtered_list();
  }

}

Register that file with the autoloader by adding this to MYMODULE.info:

files[] = includes/views/views_handler_filter_MYMODULE_country.inc

Finally, implement hook_field_views_data_alter() to force Views to use your new handler, changing the $field['field_name'] condition (and other similar strings based on field_address) to whatever makes sense for your site

function MYMODULE_field_views_data_alter(&amp;$result, $field, $module) {
  // Limit country exposed filters.
  if ($module == 'addressfield' &amp;&amp; $field['field_name'] == 'field_address') {
    $result['field_data_field_address']['field_address_country']['filter']['handler'] = 'views_handler_filter_MYMODULE_country';
  }
}