From aa7a7a14a85dddd305440771ce1c05174c7c337e Mon Sep 17 00:00:00 2001 From: Andrew West Date: Wed, 6 May 2015 13:48:51 +0100 Subject: [PATCH] CRM-13596 fix for contact subtypes being overwritten --- CRM/Contact/BAO/Contact.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 0a87121abe..3b732cc179 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -2003,7 +2003,11 @@ ORDER BY civicrm_email.is_primary DESC"; !empty($params['contact_sub_type_hidden']) ) { // if profile was used, and had any subtype, we obtain it from there - $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type_hidden']) . CRM_Core_DAO::VALUE_SEPARATOR; + //CRM-13596 - add to existing contact types, rather than overwriting + $data_contact_sub_type_arr = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($data['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR)); + if (!in_array($params['contact_sub_type_hidden'], $data_contact_sub_type_arr)) { + $data['contact_sub_type'] = $data['contact_sub_type'] . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array)$params['contact_sub_type_hidden']) . CRM_Core_DAO::VALUE_SEPARATOR; + } } if ($ctype == 'Organization') { @@ -2225,14 +2229,20 @@ ORDER BY civicrm_email.is_primary DESC"; } } - $type = $data['contact_type']; - if (!empty($data['contact_sub_type'])) { - $type = $data['contact_sub_type']; - $type = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($type, CRM_Core_DAO::VALUE_SEPARATOR)); - // generally a contact even if, has multiple subtypes the parent-type is going to be one only - // and since formatCustomField() would be interested in parent type, lets consider only one subtype - // as the results going to be same. - $type = $type[0]; + //CRM-13596 - check for contact_sub_type_hidden first + if (array_key_exists('contact_sub_type_hidden', $params)) { + $type = $params['contact_sub_type_hidden']; + } + else { + $type = $data['contact_type']; + if (!empty($data['contact_sub_type'])) { + $type = $data['contact_sub_type']; + $type = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($type, CRM_Core_DAO::VALUE_SEPARATOR)); + // generally a contact even if, has multiple subtypes the parent-type is going to be one only + // and since formatCustomField() would be interested in parent type, lets consider only one subtype + // as the results going to be same. + $type = $type[0]; + } } CRM_Core_BAO_CustomField::formatCustomField($customFieldId, -- 2.25.1