Updated: Comment #2

Problem/Motivation

The Administrative area (i.e.: Province or State) is optional because certain countries don't have subdivisions of that nature (e.g.: the Netherlands).

However, while the locality (i.e.: city) is also optional (according to the xNAL standards), the addressfield module currently adds it to all address input forms (see address.inc). Further, the smallest countries I could think of (Vatican, Monaco, Gibralter, Hong Kong, Luxembourg, etc.) all have Localities according to the UPU.

If I have a list of nodes with addresses from all over the world, and I want to allow visitors to filter that list, I have an interesting usability problem...

  • visitors from countries with states / provinces will want to filter by state first
  • visitors from countries without states / provinces will want to filter by city first

Amusing fact: according to the US board on geographic names, there is a city named "Springfield" in 34 of the 50 states.

As a Site Builder trying to create a View that can filter a set of addresses from all over the world, I want to be able to add a contextual filter that filters by administrative area if it exists, or locality if it doesn't; a field that displays the admin area if it exists, or the locality if it does not, and a sort handler which allows sorting by that field.

Proposed resolution

Apply the patch, which creates a views filter and contextual filter (argument) that allows filtering by administrative area if it exists, or locality if it doesn't.

Remaining tasks

  1. Someone other than myself should review the patch and provide me with feedback or mark it as RTBC

User interface changes

  • Adds a new argument to the list of available arguments in Views.
  • Adds a new field to the list of available fields in Views.
  • Adds a new filter to the list of available filters in Views.
  • Adds a new sort to the list of available sorts in Views.

API changes

None.

#2787255: Provide a views filter for administrative areas

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rszrama’s picture

Hah, Springfield has nothing on my hometown name: Greenville! : )

Also, the approach sounds good. Happy to test a patch when it's ready.

mparker17’s picture

Assigned: mparker17 » Unassigned
Issue summary: View changes
Status: Active » Needs review
FileSize
13.85 KB

Okay, two-months-of-Saturdays later, I have something to submit. Turns out that views handlers are... interesting sometimes. Especially when they become "broken" for unspecified reasons.

Anyway, the patch contains an argument, field, filter and sort handler that deals with the admin area if it exists, or the locality if it does not.

Reviews / questions / comments welcome!

mparker17’s picture

Issue summary: View changes
chegor’s picture

tested with 7.x-1.1 and with the latest dev
no luck. Broken/missing handler

agrozyme’s picture

Address Field Taiwan

I'm a maintainer of Address Field Taiwan, I write a views filter for Administrative area.
It can use select list to filter Administrative area.
It has only views filter (no sorter / argument).

jenlampton’s picture

Status: Needs review » Needs work

Looks like @chegor meant to mark this task as Needs Work in #4.

marcxy’s picture

The Administrative Area (State) filter is bugged.

E.g.,

Input in "CA" and all correct fields show.
Input in "California" and nothing shows.

I would prefer to use Autocomplete, but instead am forced to tell my users to use the 2 letter abbreviation for the state when filtering.

joelpittet’s picture

@marcxy that sounds like a follow-up feature request to use an autocomplete. The value should be the ISO code because it's standard and the names are not. Example being 'US Virgin Islands' vs 'U.S. Virgin Islands' vs 'Virgin Islands'

dww’s picture

Note: I'm working on solving this for the D8 Address module. I disagree with the approach proposed here. I think you need to let the locality always be its own standalone filter. For example, in a country with both administrative areas and localities, filtering by admin area isn't enough and you'll want to drill-down via locality, too. Instead, I think you want a magic filter for administrative area that disappears if a country doesn't use admin areas. See my comments+ patches at #2787255 for more. Once that's happy and committed, it should be relatively easy for someone to backport it to the D7 addressfield if there's still interest.

Cheers,
-Derek

dww’s picture

Note: my administrative area filter is now in the Address 8.x-1.0 release. If anyone wants this for D7, the backport should be reasonably easy.

Enjoy,
-Derek