Defines a US county field type. Depends on a field representing a US state being present on the same entity bundle. This field stores the FIPS code for the county in the database.

The county field widget is a select element. The module attaches an AJAX event to a change of the US state field on the entity bundle. The state value acts as a filter for the options list of the county field.

Pre-Installation

To populate the database, before installing the module, download the CSV file (see Attachment below) of US counties to the temporary files directory on the web server. (Remove the '.txt' extension from the filename. The second extension was added as this site does not allow upload of a CSV file.)

Configuration

For a given entity bundle:

  • Add a text or list_text field type to serve as the US state.
  • Add a county field type.
  • On the instance settings form for the county field, set the administrative area field to the 'US state' field on the entity.

Display

Three field formatters are provided:

  • the 'short' county name (omits the suffix like 'county' or 'parish'),
  • the 'full' county name (default),
  • FIPS code.

The FIPS code may be appended to the display of the first two formatters.

Views

The module provides two filter handlers. Otherwise, the default behavior for a 'Field API' field applies. This means:

  • any of the three formatters may be selected to determine the display value.
  • sorting is based on the FIPS code in the database. This corresponds to an alpha sort on the state-county name. If a display sorts by county and includes county values for multiple states, then this may not be the desired sort. If the FIPS code is included, then the sort order should be apparent. However, this may not be the typical use case.
  • filtering may be based on the FIPS code or the county name in the database.
  • contextual filtering is based on the FIPS code in the database.

Alternatives

As of this posting, I am not aware of any, hence this module. If there is one, someone please let me know. The 'logical' choices would be Address Field or Location, but neither supports the county (or sub-administrative area). Address Field has a column in its table for this value but beyond that does not seem to support it; e.g. it does not provide an options list for the county field. Location does not 'address' the county value.

If Commerce or Ubercart support a county value in their address components without requiring the overhead of themselves, someone let me know.

Use Cases

At present, for my purposes, a stand-alone county field is sufficient. Should it be necessary to integrate this with an address, then look for changes to this module and/or a patch to one of the modules mentioned above. Or someone else can contribute the code.

AttachmentSize
county_fips.csv_.txt120.49 KB

Project information

Releases