You are here

function wf_crm_state_abbr in Webform CiviCRM Integration 7.5

Same name and namespace in other branches
  1. 7.3 webform_civicrm_utils.inc \wf_crm_state_abbr()
  2. 7.4 includes/utils.inc \wf_crm_state_abbr()

Match a state/province id to its abbr. and vice-versa

Parameters

$input: User input (state province id or abbr)

$ret: String: 'abbreviation' or 'id'

$country_id: Int: (optional) must be supplied if fetching id from abbr

Return value

string or integer

5 calls to wf_crm_state_abbr()
webform_civicrm_update_6203 in ./webform_civicrm.install
Support new state/prov chain-select feature.
wf_crm_webform_ajax::county in includes/wf_crm_webform_ajax.inc
Populate a county list based on chosen state
wf_crm_webform_base::loadContact in includes/wf_crm_webform_base.inc
Fetch all relevant data for a given contact Used to load contacts for pre-filling a webform, and also to fill in a contact via ajax
wf_crm_webform_postprocess::findDuplicateContact in includes/wf_crm_webform_postprocess.inc
Search for an existing contact using configured deupe rule
wf_crm_webform_postprocess::saveContactLocation in includes/wf_crm_webform_postprocess.inc
Save location data for a contact

File

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

Code

function wf_crm_state_abbr($input, $ret = 'abbreviation', $country_id = NULL) {
  $params = [
    'sequential' => 1,
  ];
  if ($ret == 'id') {
    $params['abbreviation'] = $input;
    if (!$country_id || $country_id === 'default') {
      $country_id = (int) wf_crm_get_civi_setting('defaultContactCountry', 1228);
    }
  }
  else {
    $params['id'] = $input;
  }
  $params['country_id'] = $country_id;
  $result = wf_crm_apivalues('StateProvince', 'get', $params, $ret);
  return wf_crm_aval($result, 0);
}