This module provides many country related tasks.

  1. A fieldable countries database with an administrative interface.
  2. A way to alter Drupals core country list.
  3. A FAPI element named 'country'.
  4. A countries field.
  5. Integration with Country Icons.
  6. Token support.
  7. Up to date countries database including Bonaire, Sint Eustatius and Saba BES, Curaçao CUW, South Sudan SSD, Sint Maarten (Dutch part) SXM which are not covered by Drupal core.

Programming notes

FAPI elements

The module contains an example module that demonstrates multiple ways of using the country FAPI element. This includes two approaches that use no dependencies with anything other than the Drupal 7.

Read the latest version here: countries example module.

Programmatically saving an entity with countries field

This applies to any field that implements a core Options list.

  $node = new stdClass;
  $node->language = LANGUAGE_NONE;
  $node->type = 'page';

  // and some other properties ...

  $node->field_country[$node->language] = array(
    array(
      'iso2' => 'ES',
    ),
    array(
      'iso2' => 'AR',
    ),
  );

  node_save($node);

Code snippet to convert text field to country field

A simple sample script to move from a regular text field used to store countries to a Drupal country field using levenshtein and a DB of country names translations (relies on pecl-syck). By drzraf.

http://drupal.org/files/country-cleanup.txt