CRM_Contact_BAO_Contact::add handle serialized contact_sub_type also
authorSandor Semsey <semseysandor@gmail.com>
Fri, 20 Oct 2023 12:49:29 +0000 (14:49 +0200)
committerSandor Semsey <sandor@es-progress.hu>
Mon, 23 Oct 2023 21:19:39 +0000 (23:19 +0200)
Co-authored-by: colemanw <coleman@civicrm.org>
CRM/Contact/BAO/Contact.php

index a9c772dc4157cc2c97fc43d4dbe12167d6ad40f9..fc3435e30f4f6afe9362b63bac77fb1d40b6bfba 100644 (file)
@@ -119,8 +119,10 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact implements Civi\Co
           // CRM-7925
           throw new CRM_Core_Exception(ts('The Contact Sub Type does not match the Contact type for this record'));
         }
-        // Cast to array as serialization in CRM_Core_DAO::copyValues() will happen only if it is an array.
-        $params['contact_sub_type'] = (array) ($params['contact_sub_type']);
+        // Ensure value is an array so it can be handled properly by `copyValues()`
+        if (is_string($params['contact_sub_type'])) {
+          $params['contact_sub_type'] = CRM_Core_DAO::unSerializeField($params['contact_sub_type'], self::fields()['contact_sub_type']['serialize']);
+        }
       }
     }