You are here

function countries_admin_form in Countries 7

Same name and namespace in other branches
  1. 8 countries.admin.inc \countries_admin_form()
  2. 7.2 countries.admin.inc \countries_admin_form()

Generate a country form.

See also

countries_admin_form_validate()

countries_admin_form_submit()

1 string reference to 'countries_admin_form'
countries_admin_page in ./countries.admin.inc
Menu callback; Display a country form.

File

./countries.admin.inc, line 116
Admin page callbacks for the Countries module.

Code

function countries_admin_form($form, &$form_state, $country) {

  // Menu callbacks do not have page titles.
  if ($country->cid) {
    drupal_set_title(t('Edit country %title', array(
      '%title' => $country->name,
    )), PASS_THROUGH);
  }
  $form = array();
  $form['cid'] = array(
    '#type' => 'value',
    '#value' => $country->cid,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $country->name,
    '#description' => t('Specify a unique name for this country.'),
    '#required' => TRUE,
    '#maxlength' => 95,
  );
  $iso2_editable = TRUE;
  if (!empty($country->iso2)) {
    include_once DRUPAL_ROOT . '/includes/iso.inc';
    $core_countries = _country_get_predefined_list();
    $iso2_editable = !array_key_exists($country->iso2, $core_countries);
  }
  if ($iso2_editable) {
    $form['iso2'] = array(
      '#type' => 'textfield',
      '#title' => t('ISO alpha-2 code'),
      '#default_value' => $country->iso2,
      '#description' => t('Specify a unique ISO2 code for this country. This is used as the key to this country, changing it may result in the loss of data.'),
      '#required' => TRUE,
      '#maxlength' => 2,
    );
  }
  else {
    $form['iso2'] = array(
      '#type' => 'value',
      '#value' => $country->iso2,
    );
    $form['iso2']['iso2_info'] = array(
      '#type' => 'textfield',
      '#title' => t('ISO alpha-2 code'),
      '#value' => $country->iso2,
      '#disabled' => TRUE,
      '#description' => t('Core country ISO2 codes are not editable.'),
    );
  }
  $form['iso3'] = array(
    '#type' => 'textfield',
    '#title' => t('ISO alpha-3 code'),
    '#default_value' => $country->iso3,
    '#description' => t('Specify a unique ISO3 code for this country.'),
    '#required' => FALSE,
    '#maxlength' => 3,
  );
  $form['official_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Official name'),
    '#default_value' => $country->official_name,
    '#description' => t('Specify the unique official name for this country.'),
    '#required' => FALSE,
    '#maxlength' => 127,
  );
  $form['numcode'] = array(
    '#type' => 'textfield',
    '#title' => t('ISO numeric-3 code'),
    '#default_value' => empty($country->numcode) ? '' : $country->numcode,
    '#description' => t('Specify a unique number code for this country.'),
    '#required' => FALSE,
    '#maxlength' => 5,
  );
  $form['continent'] = array(
    '#type' => 'select',
    '#title' => t('Continent'),
    '#options' => countries_get_continents(),
    '#default_value' => $country->continent,
    '#required' => TRUE,
  );
  $form['enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enabled'),
    '#default_value' => $country->enabled,
  );
  if (!empty($country->iso2)) {
    $form['#country'] = $country;
  }
  $country = (object) $country;
  field_attach_form('country', $country, $form, $form_state);
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 100,
  );
  return $form;
}