From fec7a2daa356a78f9fdbf8055cfc0b2c42b73459 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Wed, 23 Jan 2019 20:25:08 +0000 Subject: [PATCH] If a profile is used to create a contact with a subtype the contact will not have any existing subtypes --- CRM/Contact/BAO/Contact.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 4dbe7fd8b5..9b65d00fed 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -2121,11 +2121,17 @@ ORDER BY civicrm_email.is_primary DESC"; ) { // if profile was used, and had any subtype, we obtain it from there //CRM-13596 - add to existing contact types, rather than overwriting - $data_contact_sub_type_arr = CRM_Utils_Array::explodePadded($data['contact_sub_type']); - if (!in_array($params['contact_sub_type_hidden'], $data_contact_sub_type_arr)) { - //CRM-20517 - make sure contact_sub_type gets the correct delimiters - $data['contact_sub_type'] = trim($data['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR); - $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . $data['contact_sub_type'] . CRM_Utils_Array::implodePadded($params['contact_sub_type_hidden']); + if (empty($data['contact_sub_type'])) { + // If we don't have a contact ID the $data['contact_sub_type'] will not be defined... + $data['contact_sub_type'] = CRM_Utils_Array::implodePadded($params['contact_sub_type_hidden']); + } + else { + $data_contact_sub_type_arr = CRM_Utils_Array::explodePadded($data['contact_sub_type']); + if (!in_array($params['contact_sub_type_hidden'], $data_contact_sub_type_arr)) { + //CRM-20517 - make sure contact_sub_type gets the correct delimiters + $data['contact_sub_type'] = trim($data['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR); + $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . $data['contact_sub_type'] . CRM_Utils_Array::implodePadded($params['contact_sub_type_hidden']); + } } } -- 2.25.1