From: Alice Frumin Date: Fri, 28 Feb 2020 16:06:59 +0000 (-0500) Subject: dev/core#1605 State/province not copied on shared address X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=653e401d2b3f65292c5a531ee9efc5e8796c20dd;p=civicrm-core.git dev/core#1605 State/province not copied on shared address --- diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index ba956c029b..2e43667b73 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -783,7 +783,7 @@ INNER JOIN civicrm_contact contact_target ON ( contact_target.id = act.contact_i // Normal update process will automatically create new address with submitted values // 1. loop through entire submitted address array - $skipFields = ['is_primary', 'location_type_id', 'is_billing', 'master_id', 'add_relationship']; + $skipFields = ['is_primary', 'location_type_id', 'is_billing', 'master_id', 'add_relationship', 'id', 'contact_id']; foreach ($address as & $values) { // 2. check if "Use another contact's address" is checked, if not continue // Additionally, if master_id is set (address was shared), set master_id to empty value. @@ -802,25 +802,22 @@ INNER JOIN civicrm_contact contact_target ON ( contact_target.id = act.contact_i $masterAddress->id = CRM_Utils_Array::value('master_id', $values); $masterAddress->find(TRUE); - // 4. modify submitted params and update it with shared contact address - // make sure you preserve specific form values like location type, is_primary_ is_billing, master_id - // CRM-10336: Also empty any fields from the existing address block if they don't exist in master (otherwise they will persist) + // 4. CRM-10336: Empty all fields (execept the fields to skip) foreach ($values as $field => $submittedValue) { + if (!in_array($field, $skipFields)) { + $values[$field] = ''; + } + } + + // 5. update address params to match shared address + // make sure you preserve specific form values like location type, is_primary_ is_billing, master_id + foreach ($masterAddress as $field => $value) { if (!in_array($field, $skipFields)) { if (isset($masterAddress->$field)) { $values[$field] = $masterAddress->$field; } - else { - $values[$field] = ''; - } } } - - //5. modify the params to include county_id if it exist in master contact. - // CRM-16152: This is a hack since QF does not submit disabled field. - if (!empty($masterAddress->county_id) && empty($values['county_id'])) { - $values['county_id'] = $masterAddress->county_id; - } } }