You are here

function country_save in Countries 7

Same name and namespace in other branches
  1. 8 countries.module \country_save()
  2. 7.2 countries.module \country_save()

Saves a country.

Parameters

$country The country object to save.:

$iso2 The original iso2 code is required for updates.: Use FALSE if it is a new records / inserts.

2 calls to country_save()
countries_admin_form_submit in ./countries.admin.inc
Process country form submissions.
countries_admin_import_form_submit in ./countries.admin.inc

File

./countries.module, line 97

Code

function country_save(&$country, $iso2 = FALSE) {
  field_attach_presave('country', $country);
  if ($iso2) {
    if ($country->iso2 != $iso2) {
      db_update('countries_country')
        ->fields(array(
        'iso2' => $country->iso2,
      ))
        ->condition('iso2', $iso2)
        ->execute();
    }
    drupal_write_record('countries_country', $country, array(
      'iso2',
    ));
    field_attach_update('country', $country);
    field_cache_clear();
  }
  else {
    drupal_write_record('countries_country', $country);
    field_attach_insert('country', $country);
  }

  // TODO: I18n
  // countries_locale_process($country);
}