You are here

README.txt in Countries 7

Same filename and directory in other branches
  1. 8 README.txt
  2. 7.2 README.txt
Countries module - http://drupal.org/project/countries
======================================================

DESCRIPTION
------------
This module provides four country related tasks.

 * A countries database with an administrative interface.
 * A way to alter Drupals core country list.
 * A country FAPI element.
 * A countries field.

REQUIREMENTS
------------
Drupal 7.x

INSTALLATION
------------
1.  To install the module copy the 'countries' folder to your 
    sites/all/modules directory.

2.  Go to admin/build/modules. Enable the module.
    It is found in the Others section.

Read more about installing modules at http://drupal.org/node/70151

UPGRADING
---------
Any updates should be automatic. Just remember to run update.php!

## Prerelease upgrades ##

If you have installed the CVS version prior to 2009-10-11, you will need to
manually change the database column {countries_country}.printable_name to
{countries_country}.official_name. No releases require this change.

FEATURES
--------

1 - Countries database

This is a simple table based on the ISO 3166-1 alpha-2 codes [1]. It covers the
countries standard name, official name, ISO 3166-1 alpha-3 code, UN numeric code
(ISO 3166-1 numeric-3) and continent (Africa, Antarctica, Asia, Europe, North
America, Oceania, South America). An enabled flag defines a countries status.

For example, Taiwan has the following values:

 * Name           - Taiwan
 * Offical name   - Taiwan, Republic of China
 * ISO alpha-2    - TW
 * ISO alpha-3    - TWN
 * ISO numeric-3  - 158
 * Continent      - Asia
 * Enabled        - Yes

The official names were taken from WikiPedia [2] and the majority of the
continent information was imported from Country codes API project [3].

Please report any omissions / errors.

I have no plans to create a "Countries bundle", which would allow users to
extend this table using the Fields API. I am willing to give someone CVS access
to either create a sub-project within this module to do this or if done via
another project, access to make requires changes within the Countries module to
accomplish this task. And to anyone else that just wants to help!

2 - Alter Drupals core country list

The module implement hook_countries_alter() which updates any list generated
using country_get_list() to filter out any disabled countries and adds the
potential to rename these based on your personal or political preferences.

## Developers note: ##

There is no need to make this module a dependency unless you use the FAPI or
Field elements. A simple countries list should be generated using:

--------------------------------------------------------------------------------
<?php
  include_once DRUPAL_ROOT . '/includes/locale.inc';
  $countries = country_get_list();
?>
--------------------------------------------------------------------------------

To bypass any third party interaction via hook_countries_alter(), use:

--------------------------------------------------------------------------------
<php
  include_once DRUPAL_ROOT . '/includes/iso.inc';
  $countries = _country_get_predefined_list();
?>
--------------------------------------------------------------------------------

3 - A country FAPI element

After programming yet another select list with a country drop down, I
encapsulated the logic into a simple FAPI element. By default it uses
country_get_list(), so filters based on the countries status.

The simplest usage for a single select country drop down list is:

--------------------------------------------------------------------------------
<?php
  $element = array(
    '#type' => 'country',
    '#default_value' => 'AU',
  );

  // a better example for the default value would be:
  $default_country = variable_get('site_default_country', '');
  $element = array(
    '#type' => 'country',
    '#default_value' => isset($edit['iso2']) ? $edit['iso2'] : $default_country,
  );
?>
--------------------------------------------------------------------------------

Custom filters are available to bypass the default country_get_list(), to filter
based on status and continent.

--------------------------------------------------------------------------------
<?php
  $element = array(
    '#type' => 'country',
    '#default_value' => 'AU',
    '#multiple' => TRUE, // multiple select
    '#cardinality' => 4, // max. selection allowed is 4 values
    '#filters' => array(
      // enabled options should be one of these constants:
      // COUNTRIES_ALL, COUNTRIES_ENABLED, or COUNTRIES_DISABLED
      'enabled' => COUNTRIES_ENABLED,
      // The restrict by continent filter accepts an array of continent codes.
      // The default continents that are defined are [code - name]:
      // AF - Africa, AN - Antarctica, AS - Asia, EU - Europe,
      // NA - North America, OC - Oceania, SA - South America, UN - Unknown
      'continents' => array('EU', 'OC'),
    ),
  );
?>
--------------------------------------------------------------------------------

4 - A country field

Provides a standard field called "Country", with a widget "Country select list".
The default display options are:

Default (The country name)
Official name
ISO alpha-2 code
ISO alpha-3 code
ISO numeric-3 code

HOWTO / FAQ
-----------

1 - Revert the database to the original values.

Currently this is not possible. You would have to uninstall and install the
module. Any customizations, (and maybe fields), would need to be recreated and
populated

2 - Change the continent list.

These are generated using a variable_get() like this:

--------------------------------------------------------------------------------
<?php
  $continents = variable_get('countries_continents',
      countries_get_default_continents());
?>
--------------------------------------------------------------------------------

To update these, you need to set the system variable 'countries_continents'. The
easiest way to do this is to cut and paste the following into your themes 
template.php, changing the array values to suit your requirements. Load one page
on your site that uses the theme, then delete the code.

--------------------------------------------------------------------------------
<?php
  variable_set('countries_continents', array(
    'AF' => t('Africa'),
    'EA' => t('Asia & Europe'),
    'AM' => t('America'),
    'OC' => t('Oceania'),
    'AN' => t('Antarctica'),
    'UN' => t('Unknown'),
  ));
?>
--------------------------------------------------------------------------------

Any invalid continent keys that are found are converted to t('Unknown'), so
update all respective countries before deleting any existing values. Currently
there is no front-end presentation of the continent information.

3 - Hiding columns in the administrative country overview page.

Like the continents, these are dynamically generated from the system variables.
They can also be changed in a similar variable_set, like 'countries_continents'.

The name, ISO alpha-2 and enabled columns can not be removed.

--------------------------------------------------------------------------------
<?php
  // Remove the columns that you want to hide.
  variable_set('countries_admin_overview_columns', array(
    'iso3' => t('ISO3'),
    'numcode' => t('Number code'),
    'continent' => t('Continent'),
    'official_name' => t('Official name'),
  ));
?>
--------------------------------------------------------------------------------

4 - I18n support?

2009-10-11
  This is planned, but the i18n project is not even started to be ported yet.


5 - Why is the delete link hidden on some countries? Why is the edit ISO alpha-2
code disabled on some countries?

These are the countries that Drupal defines. To disable a country in the list of
countries that Drupal generates, these must be present in the database. Also
done to ensure that existing references to these countries still exist, even if
you can no longer select them when they are disabled.

6 - How does this differ from countries_api?

The countries_api is a just that, an API locked into a back-end country and
regions database that has no configurable options. It main purpose is converting
country code data from one format to another. 

From the Country codes API modules project page:

    "Typical usage would be converting a country name to its ISO2
    (or ISO3) country code."

The Countries module is based on the philosophy that only the ISO2 code can be
trusted. All other data can be modified by the sites administrator, and the ISO2
is the primary key. Then the most common country requirements are built on top
of this base, providing the input elements, etc. 

7 - Related modules

Most other related modules involve external geo-data lookups / regional data
integration.

A quick search on drupalmodules.com provided the following list

 * addresses - http://drupal.org/project/addresses
   A comprehensive module that is covers countries, regions, zip codes, postal
   formats, ...
   
 * zipcode (CCK) - http://drupal.org/project/zipcode
   Hardcode validation of the Zip codes for 8 countries.

 * GeoNames - http://drupal.org/project/geonames
   XML-based Services from GeoNames.

 * Profile Location - http://drupal.org/project/profile_location
   Region / Country profile field.

 * IP to Country - http://drupal.org/project/ip2cc
   IP to Country lookup.

 * IP-based Determination of a Visitor's Country
      - http://drupal.org/project/ip2country
   IP to Country lookup.

 * IP2Nation API - http://drupal.org/project/ip2nation
   IP to Country lookup.

 * Hostip - http://drupal.org/project/hostip
   IP to Country lookup.
    
 * GeoUser - http://drupal.org/project/geouser
   IP to Country lookup.
    
 * GeoIP API - http://drupal.org/project/geoip
   API for external database.
    
 * Country codes API - http://drupal.org/project/countries_api
   API for mapping country / region data.
    
 * Ad GeoIP - http://drupal.org/project/ad_geoip
   Adds geotargeting functionality to the Drupal advertisement module.
    
 * SIN - CCK - http://drupal.org/project/sin
   Country Social Insurance Numbers CCK field.
    
 * Country code - http://drupal.org/project/country_code
   Location content handling based on the user's IP address.
    
 * Site Country - http://drupal.org/project/site_country
   Enables site default country. (Now in core)

 * GeoSniper - http://drupal.org/project/geosniper
   User information in a block.

                  Drupal ver.  Features
                  5.x 6.x 7.x  DB IP2C IPO Flags CCK Other / Notes
ad_geoip           y   y       y   y                 ad module extension
addresses                      y                  y  Multiple fields
country_code           y       c                     Site switching
countries_api      y   y       y                     Data mapping
geoip              y   y       c   y
geonames           y   y       y   y   y
geosniper              y               y             Info block
geouser                y       c   y                 Stored against user
hostip             y               y
ip2cc              y   y           y
ip2nation          y   y       y   y   y    y
ip2country         y   y           y
profile_location   y   y       y                  -  Profile region / country
sin                y   y                          y  Social Insurance Numbers
site_country           y  core c                     Default country 
zipcode                y       c*                 y  Zipcodes
    
Key
---
DB - Country database: y - db, c - code, c* - limited code info 
IP2C - IP to Country lookup
IPO - IP to xxx. Gets geodata about the users location
Flags - Country flags
CCK - Provides CCK or Fields


AUTHOR
------
Alan D. - http://drupal.org/user/198838.

REFERENCES
----------
[1] http://www.iso.org/iso/country_codes/iso_3166_code_lists.htm
[2] http://en.wikipedia.org/wiki/List_of_countries
[3] http://drupal.org/project/countries_api

File

README.txt
View source
  1. Countries module - http://drupal.org/project/countries
  2. ======================================================
  3. DESCRIPTION
  4. ------------
  5. This module provides four country related tasks.
  6. * A countries database with an administrative interface.
  7. * A way to alter Drupals core country list.
  8. * A country FAPI element.
  9. * A countries field.
  10. REQUIREMENTS
  11. ------------
  12. Drupal 7.x
  13. INSTALLATION
  14. ------------
  15. 1. To install the module copy the 'countries' folder to your
  16. sites/all/modules directory.
  17. 2. Go to admin/build/modules. Enable the module.
  18. It is found in the Others section.
  19. Read more about installing modules at http://drupal.org/node/70151
  20. UPGRADING
  21. ---------
  22. Any updates should be automatic. Just remember to run update.php!
  23. ## Prerelease upgrades ##
  24. If you have installed the CVS version prior to 2009-10-11, you will need to
  25. manually change the database column {countries_country}.printable_name to
  26. {countries_country}.official_name. No releases require this change.
  27. FEATURES
  28. --------
  29. 1 - Countries database
  30. This is a simple table based on the ISO 3166-1 alpha-2 codes [1]. It covers the
  31. countries standard name, official name, ISO 3166-1 alpha-3 code, UN numeric code
  32. (ISO 3166-1 numeric-3) and continent (Africa, Antarctica, Asia, Europe, North
  33. America, Oceania, South America). An enabled flag defines a countries status.
  34. For example, Taiwan has the following values:
  35. * Name - Taiwan
  36. * Offical name - Taiwan, Republic of China
  37. * ISO alpha-2 - TW
  38. * ISO alpha-3 - TWN
  39. * ISO numeric-3 - 158
  40. * Continent - Asia
  41. * Enabled - Yes
  42. The official names were taken from WikiPedia [2] and the majority of the
  43. continent information was imported from Country codes API project [3].
  44. Please report any omissions / errors.
  45. I have no plans to create a "Countries bundle", which would allow users to
  46. extend this table using the Fields API. I am willing to give someone CVS access
  47. to either create a sub-project within this module to do this or if done via
  48. another project, access to make requires changes within the Countries module to
  49. accomplish this task. And to anyone else that just wants to help!
  50. 2 - Alter Drupals core country list
  51. The module implement hook_countries_alter() which updates any list generated
  52. using country_get_list() to filter out any disabled countries and adds the
  53. potential to rename these based on your personal or political preferences.
  54. ## Developers note: ##
  55. There is no need to make this module a dependency unless you use the FAPI or
  56. Field elements. A simple countries list should be generated using:
  57. --------------------------------------------------------------------------------
  58. include_once DRUPAL_ROOT . '/includes/locale.inc';
  59. $countries = country_get_list();
  60. ?>
  61. --------------------------------------------------------------------------------
  62. To bypass any third party interaction via hook_countries_alter(), use:
  63. --------------------------------------------------------------------------------
  64. include_once DRUPAL_ROOT . '/includes/iso.inc';
  65. $countries = _country_get_predefined_list();
  66. ?>
  67. --------------------------------------------------------------------------------
  68. 3 - A country FAPI element
  69. After programming yet another select list with a country drop down, I
  70. encapsulated the logic into a simple FAPI element. By default it uses
  71. country_get_list(), so filters based on the countries status.
  72. The simplest usage for a single select country drop down list is:
  73. --------------------------------------------------------------------------------
  74. $element = array(
  75. '#type' => 'country',
  76. '#default_value' => 'AU',
  77. );
  78. // a better example for the default value would be:
  79. $default_country = variable_get('site_default_country', '');
  80. $element = array(
  81. '#type' => 'country',
  82. '#default_value' => isset($edit['iso2']) ? $edit['iso2'] : $default_country,
  83. );
  84. ?>
  85. --------------------------------------------------------------------------------
  86. Custom filters are available to bypass the default country_get_list(), to filter
  87. based on status and continent.
  88. --------------------------------------------------------------------------------
  89. $element = array(
  90. '#type' => 'country',
  91. '#default_value' => 'AU',
  92. '#multiple' => TRUE, // multiple select
  93. '#cardinality' => 4, // max. selection allowed is 4 values
  94. '#filters' => array(
  95. // enabled options should be one of these constants:
  96. // COUNTRIES_ALL, COUNTRIES_ENABLED, or COUNTRIES_DISABLED
  97. 'enabled' => COUNTRIES_ENABLED,
  98. // The restrict by continent filter accepts an array of continent codes.
  99. // The default continents that are defined are [code - name]:
  100. // AF - Africa, AN - Antarctica, AS - Asia, EU - Europe,
  101. // NA - North America, OC - Oceania, SA - South America, UN - Unknown
  102. 'continents' => array('EU', 'OC'),
  103. ),
  104. );
  105. ?>
  106. --------------------------------------------------------------------------------
  107. 4 - A country field
  108. Provides a standard field called "Country", with a widget "Country select list".
  109. The default display options are:
  110. Default (The country name)
  111. Official name
  112. ISO alpha-2 code
  113. ISO alpha-3 code
  114. ISO numeric-3 code
  115. HOWTO / FAQ
  116. -----------
  117. 1 - Revert the database to the original values.
  118. Currently this is not possible. You would have to uninstall and install the
  119. module. Any customizations, (and maybe fields), would need to be recreated and
  120. populated
  121. 2 - Change the continent list.
  122. These are generated using a variable_get() like this:
  123. --------------------------------------------------------------------------------
  124. $continents = variable_get('countries_continents',
  125. countries_get_default_continents());
  126. ?>
  127. --------------------------------------------------------------------------------
  128. To update these, you need to set the system variable 'countries_continents'. The
  129. easiest way to do this is to cut and paste the following into your themes
  130. template.php, changing the array values to suit your requirements. Load one page
  131. on your site that uses the theme, then delete the code.
  132. --------------------------------------------------------------------------------
  133. variable_set('countries_continents', array(
  134. 'AF' => t('Africa'),
  135. 'EA' => t('Asia & Europe'),
  136. 'AM' => t('America'),
  137. 'OC' => t('Oceania'),
  138. 'AN' => t('Antarctica'),
  139. 'UN' => t('Unknown'),
  140. ));
  141. ?>
  142. --------------------------------------------------------------------------------
  143. Any invalid continent keys that are found are converted to t('Unknown'), so
  144. update all respective countries before deleting any existing values. Currently
  145. there is no front-end presentation of the continent information.
  146. 3 - Hiding columns in the administrative country overview page.
  147. Like the continents, these are dynamically generated from the system variables.
  148. They can also be changed in a similar variable_set, like 'countries_continents'.
  149. The name, ISO alpha-2 and enabled columns can not be removed.
  150. --------------------------------------------------------------------------------
  151. // Remove the columns that you want to hide.
  152. variable_set('countries_admin_overview_columns', array(
  153. 'iso3' => t('ISO3'),
  154. 'numcode' => t('Number code'),
  155. 'continent' => t('Continent'),
  156. 'official_name' => t('Official name'),
  157. ));
  158. ?>
  159. --------------------------------------------------------------------------------
  160. 4 - I18n support?
  161. 2009-10-11
  162. This is planned, but the i18n project is not even started to be ported yet.
  163. 5 - Why is the delete link hidden on some countries? Why is the edit ISO alpha-2
  164. code disabled on some countries?
  165. These are the countries that Drupal defines. To disable a country in the list of
  166. countries that Drupal generates, these must be present in the database. Also
  167. done to ensure that existing references to these countries still exist, even if
  168. you can no longer select them when they are disabled.
  169. 6 - How does this differ from countries_api?
  170. The countries_api is a just that, an API locked into a back-end country and
  171. regions database that has no configurable options. It main purpose is converting
  172. country code data from one format to another.
  173. From the Country codes API modules project page:
  174. "Typical usage would be converting a country name to its ISO2
  175. (or ISO3) country code."
  176. The Countries module is based on the philosophy that only the ISO2 code can be
  177. trusted. All other data can be modified by the sites administrator, and the ISO2
  178. is the primary key. Then the most common country requirements are built on top
  179. of this base, providing the input elements, etc.
  180. 7 - Related modules
  181. Most other related modules involve external geo-data lookups / regional data
  182. integration.
  183. A quick search on drupalmodules.com provided the following list
  184. * addresses - http://drupal.org/project/addresses
  185. A comprehensive module that is covers countries, regions, zip codes, postal
  186. formats, ...
  187. * zipcode (CCK) - http://drupal.org/project/zipcode
  188. Hardcode validation of the Zip codes for 8 countries.
  189. * GeoNames - http://drupal.org/project/geonames
  190. XML-based Services from GeoNames.
  191. * Profile Location - http://drupal.org/project/profile_location
  192. Region / Country profile field.
  193. * IP to Country - http://drupal.org/project/ip2cc
  194. IP to Country lookup.
  195. * IP-based Determination of a Visitor's Country
  196. - http://drupal.org/project/ip2country
  197. IP to Country lookup.
  198. * IP2Nation API - http://drupal.org/project/ip2nation
  199. IP to Country lookup.
  200. * Hostip - http://drupal.org/project/hostip
  201. IP to Country lookup.
  202. * GeoUser - http://drupal.org/project/geouser
  203. IP to Country lookup.
  204. * GeoIP API - http://drupal.org/project/geoip
  205. API for external database.
  206. * Country codes API - http://drupal.org/project/countries_api
  207. API for mapping country / region data.
  208. * Ad GeoIP - http://drupal.org/project/ad_geoip
  209. Adds geotargeting functionality to the Drupal advertisement module.
  210. * SIN - CCK - http://drupal.org/project/sin
  211. Country Social Insurance Numbers CCK field.
  212. * Country code - http://drupal.org/project/country_code
  213. Location content handling based on the user's IP address.
  214. * Site Country - http://drupal.org/project/site_country
  215. Enables site default country. (Now in core)
  216. * GeoSniper - http://drupal.org/project/geosniper
  217. User information in a block.
  218. Drupal ver. Features
  219. 5.x 6.x 7.x DB IP2C IPO Flags CCK Other / Notes
  220. ad_geoip y y y y ad module extension
  221. addresses y y Multiple fields
  222. country_code y c Site switching
  223. countries_api y y y Data mapping
  224. geoip y y c y
  225. geonames y y y y y
  226. geosniper y y Info block
  227. geouser y c y Stored against user
  228. hostip y y
  229. ip2cc y y y
  230. ip2nation y y y y y y
  231. ip2country y y y
  232. profile_location y y y - Profile region / country
  233. sin y y y Social Insurance Numbers
  234. site_country y core c Default country
  235. zipcode y c* y Zipcodes
  236. Key
  237. ---
  238. DB - Country database: y - db, c - code, c* - limited code info
  239. IP2C - IP to Country lookup
  240. IPO - IP to xxx. Gets geodata about the users location
  241. Flags - Country flags
  242. CCK - Provides CCK or Fields
  243. AUTHOR
  244. ------
  245. Alan D. - http://drupal.org/user/198838.
  246. REFERENCES
  247. ----------
  248. [1] http://www.iso.org/iso/country_codes/iso_3166_code_lists.htm
  249. [2] http://en.wikipedia.org/wiki/List_of_countries
  250. [3] http://drupal.org/project/countries_api