protected $_dedupeFields;
+ protected static $customFields;
+
/**
* Attempt to match header labels with our mapper fields
* FIXME: This is essentially the same function as parent::defaultFromHeader
}
}
+ $formattedFieldNames = $this->formatCustomFieldName($this->_mapperFields);
+ self::$customFields = CRM_Core_BAO_CustomField::getFields($this->_contactType);
+ foreach(self::$customFields as $key => $attr) {
+ if (!empty($attr['is_required'])) {
+ $highlightedFields[] = "custom_$key";
+ }
+ }
$this->assign('highlightedFields', $highlightedFields);
- $this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $this->formatCustomFieldName($this->_mapperFields));
+ $this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $formattedFieldNames);
$columnNames = array();
//get original col headers from csv if present.
*/
function formatCustomFieldName(&$fields) {
//CRM-2676, replacing the conflict for same custom field name from different custom group.
- $fieldIds = $formattedFieldNames = array();
+ $fieldIds = $formattedFieldNames = self::$customFields = array();
foreach ($fields as $key => $value) {
if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) {
$fieldIds[] = $customFieldId;
if (!array_key_exists($customFieldID, $customFields)) {
self::addToErrorMsg(ts('field ID'), $errorMessage);
}
+
+ if ($customFields[$customFieldID]['is_required'] && (empty($params['custom_'.$customFieldID]) && $params['custom_'.$customFieldID] !== 0) && $customFields[$customFieldID]['data_type'] == 'Boolean') {
+ self::addToErrorMsg($customFields[$customFieldID]['label'].'::'.$customFields[$customFieldID]['groupTitle'], $errorMessage);
+ }
+
//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, $addressCustomFields)) {
self::formatCustomDate($params, $formatted, $dateType, $key);
}
elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
- $params[$key] = CRM_Utils_String::strtoboolstr($val);
+ if (empty($val) && !empty($params['id']) && !is_numeric($val) && $this->_onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) {
+ unset($params[$key]);
+ }
+ else {
+ $params[$key] = CRM_Utils_String::strtoboolstr($val);
}
}
$params[$key] = $this->checkGender($val);
}
}
+ }
//now format custom data.
foreach ($params as $key => $field) {
- if (!isset($field) || empty($field)){
- unset($params[$key]);
- continue;
- }
-
if (is_array($field)) {
$isAddressCustomField = FALSE;
foreach ($field as $value) {
$cfTable.default_value,
$cfTable.options_per_line, $cfTable.text_length,
$cfTable.custom_group_id,
+ $cfTable.is_required,
$cgTable.extends, $cfTable.is_search_range,
$cgTable.extends_entity_column_value,
$cgTable.extends_entity_column_id,
$fields[$dao->id]['option_group_id'] = $dao->option_group_id;
$fields[$dao->id]['date_format'] = $dao->date_format;
$fields[$dao->id]['time_format'] = $dao->time_format;
+ $fields[$dao->id]['is_required'] = $dao->is_required;
}
CRM_Core_BAO_Cache::setItem($fields,