You are here

function wf_crm_get_states in Webform CiviCRM Integration 7.5

Same name and namespace in other branches
  1. 7.4 includes/utils.inc \wf_crm_get_states()

Get list of states, keyed by abbreviation rather than ID.

Parameters

null|int|string $param:

Return value

array

4 calls to wf_crm_get_states()
wf_crm_admin_component::alterForm in includes/wf_crm_admin_component.inc
Alter back-end webform component edit forms. Called by hook_form_alter() whenever editing a webform component.
wf_crm_webform_ajax::stateProvince in includes/wf_crm_webform_ajax.inc
Populate a state list based on chosen country
wf_crm_webform_postprocess::validateThisPage in includes/wf_crm_webform_postprocess.inc
Recursive validation callback for webform page submission
wf_crm_webform_preprocess::addResources in includes/wf_crm_webform_preprocess.inc
Add necessary js & css to the form

File

includes/utils.inc, line 175
Webform CiviCRM module's common utility functions.

Code

function wf_crm_get_states($param = NULL) {
  $ret = [];
  if (!$param || $param == 'default') {
    $provinceLimit = wf_crm_get_civi_setting('provinceLimit');
    if (!$param && $provinceLimit) {
      $param = (array) $provinceLimit;
    }
    else {
      $param = [
        (int) wf_crm_get_civi_setting('defaultContactCountry', 1228),
      ];
    }
  }
  else {
    $param = [
      (int) $param,
    ];
  }
  $states = wf_crm_apivalues('state_province', 'get', [
    'return' => 'abbreviation,name',
    'sort' => 'name',
    'country_id' => [
      'IN' => $param,
    ],
  ]);
  foreach ($states as $state) {
    $ret[strtoupper($state['abbreviation'])] = $state['name'];
  }

  // Localize the state/province names if in an non-en_US locale
  $tsLocale = CRM_Utils_System::getUFLocale();
  if ($tsLocale != '' and $tsLocale != 'en_US') {
    $i18n = CRM_Core_I18n::singleton();
    $i18n
      ->localizeArray($ret, [
      'context' => 'province',
    ]);
    CRM_Utils_Array::asort($ret);
  }
  return $ret;
}