public function Utils::wf_crm_get_states in Webform CiviCRM Integration 8.5
Get list of states, keyed by abbreviation rather than ID.
Parameters
null|int|string $param:
bool $isBilling:
Overrides UtilsInterface::wf_crm_get_states
File
- src/
Utils.php, line 68 - Webform CiviCRM module's common utility functions.
Class
Namespace
Drupal\webform_civicrmCode
public function wf_crm_get_states($param = NULL, $isBilling = FALSE) {
$ret = [];
if (!$param || $param == 'default') {
$settings = $this
->wf_civicrm_api('Setting', 'get', [
'sequential' => 1,
'return' => 'provinceLimit',
]);
$provinceLimit = wf_crm_aval($settings, "values:0:provinceLimit");
if (!$param && $provinceLimit) {
$param = (array) $provinceLimit;
}
else {
$settings = $this
->wf_civicrm_api('Setting', 'get', [
'sequential' => 1,
'return' => 'defaultContactCountry',
]);
$param = [
(int) wf_crm_aval($settings, "values:0:defaultContactCountry", 1228),
];
}
}
else {
$param = [
(int) $param,
];
}
$states = $this
->wf_crm_apivalues('state_province', 'get', [
'return' => 'abbreviation,name',
'sort' => 'name',
'country_id' => [
'IN' => $param,
],
]);
foreach ($states as $state) {
$key = $isBilling ? 'id' : 'abbreviation';
$ret[strtoupper($state[$key])] = $state['name'];
}
// Localize the state/province names if in an non-en_US locale
$tsLocale = \CRM_Utils_System::getUFLocale();
if ($tsLocale !== '' && $tsLocale !== 'en_US') {
$i18n = \CRM_Core_I18n::singleton();
$i18n
->localizeArray($ret, [
'context' => 'province',
]);
\CRM_Utils_Array::asort($ret);
}
return $ret;
}