From 4985cc60a35e53181d0d2b3c4e80d5e33ce0337c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 18 Jan 2019 17:10:37 -0500 Subject: [PATCH] Fix address field regression --- includes/wf_crm_webform_postprocess.inc | 28 +++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/includes/wf_crm_webform_postprocess.inc b/includes/wf_crm_webform_postprocess.inc index 5c6b1193f..c5ff597f4 100644 --- a/includes/wf_crm_webform_postprocess.inc +++ b/includes/wf_crm_webform_postprocess.inc @@ -752,6 +752,23 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base { $is_primary_address_location_type = wf_crm_aval($contact, 'address:1:location_type_id'); $is_primary_email_location_type = wf_crm_aval($contact, 'email:1:location_type_id'); + // Fix address fields. + if (!empty($contact['address'])) { + foreach ($contact['address'] as &$address) { + // Translate state/prov abbr to id + if (!empty($address['state_province_id'])) { + $config = CRM_Core_Config::singleton(); + if (!($address['state_province_id'] = wf_crm_state_abbr($address['state_province_id'], 'id', wf_crm_aval($address, 'country_id', $config->defaultContactCountry)))) { + $address['state_province_id'] = ''; + } + } + // Substitute county stub ('-' is a hack to get around required field when there are no available counties) + if (isset($address['county_id']) && $address['county_id'] === '-') { + $address['county_id'] = ''; + } + } + } + foreach (wf_crm_location_fields() as $location) { if (!empty($contact[$location])) { $existing = array(); @@ -766,17 +783,6 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base { $existing = array_merge(array(array()), $result['values']); } foreach ($contact[$location] as $i => $params) { - // Translate state/prov abbr to id - if (!empty($params['state_province_id'])) { - $config = CRM_Core_Config::singleton(); - if (!($params['state_province_id'] = wf_crm_state_abbr($params['state_province_id'], 'id', wf_crm_aval($params, 'country_id', $config->defaultContactCountry)))) { - $params['state_province_id'] = ''; - } - } - // Substitute county stub ('-' is a hack to get around required field when there are no available counties) - if (isset($params['county_id']) && $params['county_id'] === '-') { - $params['county_id'] = ''; - } // Update drupal email address if ($location == 'email' && !empty($params['email']) && $i == 1) { $uid = wf_crm_user_cid($cid, 'contact');