You are here

function _location_province_select_options in Location 5

The array that is returned is a complete list of state/provinces that belong to the countries enabled by the site's location system.

Parameters

$value : A preselected value for the HTML select form item that is returned.

$required: A boolean for whether or not the field should be required.

$country: If you wish to only serve a state/province selection for a particular country while leaving out state/provinces by all other countries, pass the lower case of the country's two-letter ISO 3166 code in this parameter. If you wish to serve a province selection from all countries, pass NULL for this parameter.

$form_name: A non-spaced string for the generated HTML form item's "name" attribute. If 'location' is passed, the generated HTML input field's name will be "edit[location][province]".

Return value

An associative array where -> the keys are a contatenation of the countrycode and a three digit positive integer unique to each province within a country's provinces -> the values are the full name of the province

2 calls to _location_province_select_options()
location_form in ./location.inc
Generates a Drupal HTML form for collecting locationes.
location_province_select_options in ./location.inc
This function is a public wrapper for the above function

File

./location.inc, line 1240

Code

function _location_province_select_options($value = '', $required = FALSE, $country = NULL) {
  $options_list = array();
  $options_list[''] = '';
  $options_list['xx'] = t('NOT LISTED');
  if (count($countrycodes) == 1 || $country) {
    if (!$country) {
      $countrycodes = location_configured_countries();
      $countrycodes = array_keys($countrycodes);
      $country = $countrycodes[0];
    }
    $province_listing_function = 'location_province_list_' . $country;

    // Trying to return options in case of only 1 country is configured into system or if $country != null
    if (function_exists($province_listing_function)) {
      $province_list = $province_listing_function();
      if (count($province_list)) {
        $options_list[$country . '000'] = '[ ----- ' . t('MAKE A SELECTION') . ' ----- ]';
        foreach ($province_list as $province_code => $province_name) {
          $options_list[$country . '-' . $province_code] = $province_name;
        }
      }
    }
  }
  else {
    $countrycodes = location_configured_countries();
    $countrycodes = array_flip($countrycodes);
    foreach ($countrycodes as $country_name => $country_code) {

      // Load country specifice code .inc file if it exists.
      // For example, if country_code for U.S. == 'us', load location.us.inc
      $include_file = LOCATION_PATH . '/supported/location.' . $country_code . '.inc';
      $province_listing_function = 'location_province_list_' . $country_code;
      if (function_exists($province_listing_function)) {
        $province_list = $province_listing_function();
        if (count($province_list)) {
          $options_list[$country_code . '-000'] = '[ ----- ' . strtoupper($country_name) . ' ----- ]';
          foreach ($province_list as $province_code => $province_name) {
            $options_list[$country_code . '-' . $province_code] = $province_name;
          }
        }
      }
    }
  }
  return array(
    '#type' => 'select',
    '#title' => t('State/Province'),
    '#default_value' => $value,
    '#options' => $options_list,
    '#extra' => 0,
    '#multiple' => FALSE,
    '#required' => $required,
  );
}