$this->_mapperKeys = $mapperKeys;
}
- /**
- * @param $customFieldID
- * @param $value
- * @param array $fieldMetaData
- * @param $dateType
- *
- * @return ?string
- */
- private function validateCustomField($customFieldID, $value, array $fieldMetaData, $dateType): ?string {
- // validate null values for required custom fields of type boolean
- if (!empty($fieldMetaData['is_required']) && (empty($value) && !is_numeric($value)) && $fieldMetaData['data_type'] == 'Boolean') {
- return $fieldMetaData['label'] . '::' . $fieldMetaData['groupTitle'];
- }
-
- /* validate the data against the CF type */
-
- if ($value) {
- $dataType = $fieldMetaData['data_type'];
- $htmlType = $fieldMetaData['html_type'];
- $isSerialized = CRM_Core_BAO_CustomField::isSerialized($fieldMetaData);
- if ($dataType === 'Date') {
- $params = ['date_field' => $value];
- if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, 'date_field')) {
- return NULL;
- }
- return $fieldMetaData['label'];
- }
- elseif ($dataType == 'Boolean') {
- if (CRM_Utils_String::strtoboolstr($value) === FALSE) {
- return $fieldMetaData['label'] . '::' . $fieldMetaData['groupTitle'];
- }
- }
- // need not check for label filed import
- $selectHtmlTypes = [
- 'CheckBox',
- 'Select',
- 'Radio',
- ];
- if ((!$isSerialized && !in_array($htmlType, $selectHtmlTypes)) || $dataType == 'Boolean' || $dataType == 'ContactReference') {
- $valid = CRM_Core_BAO_CustomValue::typecheck($dataType, $value);
- if (!$valid) {
- return $fieldMetaData['label'];
- }
- }
-
- // check for values for custom fields for checkboxes and multiselect
- if ($isSerialized && $dataType != 'ContactReference') {
- $value = trim($value);
- $value = str_replace('|', ',', $value);
- $mulValues = explode(',', $value);
- $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
- foreach ($mulValues as $v1) {
- if (strlen($v1) == 0) {
- continue;
- }
-
- $flag = FALSE;
- foreach ($customOption as $v2) {
- if ((strtolower(trim($v2['label'])) == strtolower(trim($v1))) || (strtolower(trim($v2['value'])) == strtolower(trim($v1)))) {
- $flag = TRUE;
- }
- }
-
- if (!$flag) {
- return $fieldMetaData['label'];
- }
- }
- }
- elseif ($htmlType == 'Select' || ($htmlType == 'Radio' && $dataType != 'Boolean')) {
- $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
- $flag = FALSE;
- foreach ($customOption as $v2) {
- if ((strtolower(trim($v2['label'])) == strtolower(trim($value))) || (strtolower(trim($v2['value'])) == strtolower(trim($value)))) {
- $flag = TRUE;
- }
- }
- if (!$flag) {
- return $fieldMetaData['label'];
- }
- }
- }
-
- return NULL;
- }
-
/**
* The initializer code, called before processing.
*/
return $fieldMetadata;
}
+ /**
+ * @param $customFieldID
+ * @param $value
+ * @param array $fieldMetaData
+ * @param $dateType
+ *
+ * @return ?string
+ */
+ protected function validateCustomField($customFieldID, $value, array $fieldMetaData, $dateType): ?string {
+ // validate null values for required custom fields of type boolean
+ if (!empty($fieldMetaData['is_required']) && (empty($value) && !is_numeric($value)) && $fieldMetaData['data_type'] == 'Boolean') {
+ return $fieldMetaData['label'] . '::' . $fieldMetaData['groupTitle'];
+ }
+
+ /* validate the data against the CF type */
+
+ if ($value) {
+ $dataType = $fieldMetaData['data_type'];
+ $htmlType = $fieldMetaData['html_type'];
+ $isSerialized = CRM_Core_BAO_CustomField::isSerialized($fieldMetaData);
+ if ($dataType === 'Date') {
+ $params = ['date_field' => $value];
+ if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, 'date_field')) {
+ return NULL;
+ }
+ return $fieldMetaData['label'];
+ }
+ elseif ($dataType == 'Boolean') {
+ if (CRM_Utils_String::strtoboolstr($value) === FALSE) {
+ return $fieldMetaData['label'] . '::' . $fieldMetaData['groupTitle'];
+ }
+ }
+ // need not check for label filed import
+ $selectHtmlTypes = [
+ 'CheckBox',
+ 'Select',
+ 'Radio',
+ ];
+ if ((!$isSerialized && !in_array($htmlType, $selectHtmlTypes)) || $dataType == 'Boolean' || $dataType == 'ContactReference') {
+ $valid = CRM_Core_BAO_CustomValue::typecheck($dataType, $value);
+ if (!$valid) {
+ return $fieldMetaData['label'];
+ }
+ }
+
+ // check for values for custom fields for checkboxes and multiselect
+ if ($isSerialized && $dataType != 'ContactReference') {
+ $value = trim($value);
+ $value = str_replace('|', ',', $value);
+ $mulValues = explode(',', $value);
+ $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
+ foreach ($mulValues as $v1) {
+ if (strlen($v1) == 0) {
+ continue;
+ }
+
+ $flag = FALSE;
+ foreach ($customOption as $v2) {
+ if ((strtolower(trim($v2['label'])) == strtolower(trim($v1))) || (strtolower(trim($v2['value'])) == strtolower(trim($v1)))) {
+ $flag = TRUE;
+ }
+ }
+
+ if (!$flag) {
+ return $fieldMetaData['label'];
+ }
+ }
+ }
+ elseif ($htmlType == 'Select' || ($htmlType == 'Radio' && $dataType != 'Boolean')) {
+ $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
+ $flag = FALSE;
+ foreach ($customOption as $v2) {
+ if ((strtolower(trim($v2['label'])) == strtolower(trim($value))) || (strtolower(trim($v2['value'])) == strtolower(trim($value)))) {
+ $flag = TRUE;
+ }
+ }
+ if (!$flag) {
+ return $fieldMetaData['label'];
+ }
+ }
+ }
+
+ return NULL;
+ }
+
}