| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
+
+use Civi\Api4\Contact;
+
require_once 'CRM/Utils/DeprecatedUtils.php';
require_once 'api/v3/utils.php';
*
* @throws \CiviCRM_API3_Exception
* @throws \CRM_Core_Exception
+ * @throws \API_Exception
*/
public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) {
$config = CRM_Core_Config::singleton();
//now we create new contact in update/fill mode also.
$contactID = NULL;
if ($createNewContact || ($this->_retCode != CRM_Import_Parser::NO_MATCH && $this->_updateWithId)) {
-
- //CRM-4430, don't carry if not submitted.
- foreach (['prefix_id', 'suffix_id', 'gender_id'] as $name) {
- if (!empty($formatted[$name])) {
- $options = CRM_Contact_BAO_Contact::buildOptions($name, 'get');
- if (!isset($options[$formatted[$name]])) {
- $formatted[$name] = CRM_Utils_Array::key((string) $formatted[$name], $options);
- }
+ // @todo - there are multiple places where formatting is done that need consolidation.
+ // This handles where the label has been passed in and it has gotten this far.
+ // probably a bunch of hard-coded stuff could be removed to rely on this.
+ $fields = Contact::getFields(FALSE)
+ ->addWhere('options', '=', TRUE)
+ ->setLoadOptions(TRUE)
+ ->execute()->indexBy('name');
+ foreach ($fields as $fieldName => $fieldSpec) {
+ if (!empty($formatted[$fieldName])
+ && empty($fieldSpec['options'][$formatted[$fieldName]])) {
+ $formatted[$fieldName] = array_search($formatted[$fieldName], $fieldSpec['options'], TRUE) ?? $formatted[$fieldName];
}
}
+ //CRM-4430, don't carry if not submitted.
if ($this->_updateWithId && !empty($params['id'])) {
$contactID = $params['id'];
}
}
}
- $contact = CRM_Contact_BAO_Contact::create($data);
- $cid = $contact->id;
+ $contact = civicrm_api3('Contact', 'create', $data);
+ $cid = $contact['id'];
CRM_Core_Config::setPermitCacheFlushMode(TRUE);
* ID of entity per $extends.
*/
function _civicrm_api3_custom_format_params($params, &$values, $extends, $entityId = NULL) {
+ if (!empty($params['custom'])) {
+ // The Import class does the formatting first - ideally it wouldn't but this early return
+ // provides transitional support.
+ return;
+ }
$values['custom'] = [];
$checkCheckBoxField = FALSE;
$entity = $extends;
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- public function testPrefixLabel() {
+ public function testPrefixLabel(): void {
$this->callAPISuccess('OptionValue', 'create', ['option_group_id' => 'individual_prefix', 'name' => 'new_one', 'label' => 'special', 'value' => 70]);
$mapping = [
['name' => 'first_name', 'column_number' => 0],
/**
* Test that labels work for importing custom data.
*
+ * @throws \API_Exception
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testCustomDataLabel() {
+ public function testCustomDataLabel(): void {
$this->createCustomGroupWithFieldOfType([], 'select');
$contactValues = [
'first_name' => 'Bill',