You are here

function feeds_tamper_country_to_code_callback in Feeds Tamper 7

1 string reference to 'feeds_tamper_country_to_code_callback'
country_to_code.inc in plugins/country_to_code.inc

File

plugins/country_to_code.inc, line 25

Code

function feeds_tamper_country_to_code_callback($result, $item_key, $element_key, &$field, $settings, $source) {
  include_once DRUPAL_ROOT . '/includes/locale.inc';
  static $countries = array();
  if (empty($countries)) {
    $countries = country_get_list();
    array_walk($countries, '_feeds_tamper_country_to_code_strtolower');
    $countries = array_flip($countries);
  }

  // If it's already a valid country code, leave it alone.
  if (in_array($field, $countries)) {
    return;
  }

  // Trim whitespace, set to lowercase.
  $country = t(drupal_strtolower(trim($field)));
  if (isset($countries[$country])) {
    $field = $countries[$country];
  }
  else {

    // If country name cannot be found, return nothing.
    $field = '';
  }
}