return TRUE;
}
- /**
- * Check if an error in custom data.
- *
- * @deprecated all of this is duplicated if getTransformedValue is used.
- *
- * @param array $params
- * @param string $errorMessage
- * A string containing all the error-fields.
- *
- * @param null $csType
- */
- public function isErrorInCustomData($params, &$errorMessage, $csType = NULL) {
- $dateType = CRM_Core_Session::singleton()->get("dateTypes");
- $errors = [];
-
- if (!empty($params['contact_sub_type'])) {
- $csType = $params['contact_sub_type'] ?? NULL;
- }
-
- if (empty($params['contact_type'])) {
- $params['contact_type'] = 'Individual';
- }
-
- // get array of subtypes - CRM-18708
- if (in_array($csType, CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE)) {
- $csType = $this->getSubtypes($params['contact_type']);
- }
-
- if (is_array($csType)) {
- // fetch custom fields for every subtype and add it to $customFields array
- // CRM-18708
- $customFields = [];
- foreach ($csType as $cType) {
- $customFields += CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, FALSE, $cType);
- }
- }
- else {
- $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, FALSE, $csType);
- }
-
- foreach ($params as $key => $value) {
- if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
- //For address custom fields, we do get actual custom field value as an inner array of
- //values so need to modify
- if (!array_key_exists($customFieldID, $customFields)) {
- return ts('field ID');
- }
- /* check if it's a valid custom field id */
- $errors[] = $this->validateCustomField($customFieldID, $value, $customFields[$customFieldID], $dateType);
- }
- }
- if ($errors) {
- $errorMessage .= ($errorMessage ? '; ' : '') . implode('; ', array_filter($errors));
- }
- }
-
/**
* get subtypes given the contact type
*
$this->callAPISuccessGetSingle('Contact', $contactValues);
}
- /**
- * Test the determination of whether a custom field is valid.
- */
- public function testCustomFieldValidation(): void {
- $errorMessage = '';
- $customGroup = $this->customGroupCreate([
- 'extends' => 'Contact',
- 'title' => 'ABC',
- ]);
- $customField = $this->customFieldOptionValueCreate($customGroup, 'fieldABC', ['html_type' => 'Select', 'serialize' => 1]);
- $params = [
- 'custom_' . $customField['id'] => 'Label1|Label2',
- ];
- $parser = new CRM_Contact_Import_Parser_Contact();
- $parser->isErrorInCustomData($params, $errorMessage);
- $this->assertEquals(NULL, $errorMessage);
- }
-
/**
* Test the import validation.
*