diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 1980d227d4df..c4261df3cc69 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -845,46 +845,8 @@ private function formatProfileContactParams( } } else { - if (($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key))) { - // for autocomplete transfer hidden value instead of label - if ($params[$key] && isset($params[$key . '_id'])) { - $value = $params[$key . '_id']; - } - - // we need to append time with date - if ($params[$key] && isset($params[$key . '_time'])) { - $value .= ' ' . $params[$key . '_time']; - } - - // if auth source is not checksum / login && $value is blank, do not proceed - CRM-10128 - if (($session->get('authSrc') & (CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN)) == 0 && - ($value == '' || !isset($value)) - ) { - continue; - } - - $valueId = NULL; - - //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 = CRM_Utils_Array::explodePadded($data['contact_sub_type']); - } - } - - CRM_Core_BAO_CustomField::formatCustomField($customFieldId, - $data['custom'], - $value, - $type, - $valueId, - $contactID, - FALSE, - FALSE - ); + if ((CRM_Core_BAO_CustomField::getKeyID($key))) { + $data[$key] = $value; } elseif ($key === 'edit') { continue; diff --git a/tests/phpunit/CRM/Contact/Import/Form/data/individual_with_custom_checkbox_field.csv b/tests/phpunit/CRM/Contact/Import/Form/data/individual_with_custom_checkbox_field.csv new file mode 100644 index 000000000000..62d17c04fd92 --- /dev/null +++ b/tests/phpunit/CRM/Contact/Import/Form/data/individual_with_custom_checkbox_field.csv @@ -0,0 +1,3 @@ +First Name,Last name,Colour +Bob,Smith,"Red,Yellow,Blue" +Mary,Smith,"1,2,3" diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index b78b6c7456a1..754ea0c835ce 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -854,6 +854,52 @@ public function testCustomDataName(): void { $this->assertEquals('Y', $contact[$this->getCustomFieldName('select')]); } + /** + * Test values import correctly when they are numbers. + * + * https://lab.civicrm.org/dev/core/-/issues/3850 + * @throws \CRM_Core_Exception + */ + public function testCustomCheckboxNumericValues(): void { + $this->createCustomGroupWithFieldOfType([], 'checkbox', '', [ + 'option_values' => [ + [ + 'label' => 'Red', + 'value' => '1', + 'weight' => 1, + 'is_active' => 1, + ], + [ + 'label' => 'Yellow', + 'value' => '2', + 'weight' => 2, + 'is_active' => 1, + ], + [ + 'label' => 'Blue', + 'value' => '3', + 'weight' => 3, + 'is_active' => 1, + ], + ], + ]); + $this->importCSV('individual_with_custom_checkbox_field.csv', [ + [0 => 'first_name'], + [0 => 'last_name'], + [0 => $this->getCustomFieldName('checkbox')], + ]); + $contacts = Contact::get()->addWhere('last_name', '=', 'Smith') + ->addSelect($this->getCustomFieldName('checkbox', 4)) + ->execute(); + $this->assertCount(2, $contacts); + foreach ($contacts as $contact) { + $this->assertEquals([1,2,3], $contact[$this->getCustomFieldName('checkbox', 4)]); + } + } + + public function testCustomAutoComplete() { + $this->createCustomGroupWithFieldOfType([], 'autocomplete'); + } /** * Test importing in the Preferred Language Field * @@ -2095,6 +2141,8 @@ protected function validateCSV(string $csv, array $mapper, array $submittedValue * e.g [['first_name']['email', 1]]. * {@see \CRM_Contact_Import_Parser_Contact::getMappingFieldFromMapperInput} * @param array $submittedValues + * + * @throws \CRM_Core_Exception */ protected function importCSV(string $csv, array $mapper, array $submittedValues = []): void { $submittedValues = array_merge([