class CRM_Custom_Import_Form_MapField extends CRM_Contact_Import_Form_MapField {
protected $_parser = 'CRM_Custom_Import_Parser_Api';
protected $_mappingType = 'Import Multi value custom data';
- protected $_highlightedFields = array();
+// protected $_highlightedFields = array();
/**
* Entity being imported to.
* @var string
$this->_columnCount = $this->get('columnCount');
$this->assign('columnCount', $this->_columnCount);
$this->_dataValues = $this->get('dataValues');
+ $highlightedFields = array();
+ $highlightedFields[] = 'contact_id';
+ $highlightedFields[] = 'external_identifier';
//Separate column names from actual values.
$columnNames = $this->_dataValues[0];
$this->_columnHeaders = $this->_dataValues[0];
}
$this->assign('rowDisplayCount', 2);
- $this->assign('highlightedFields', $this->_highlightedFields);
+ $this->assign('highlightedFields', $highlightedFields);
}
/**
foreach ($fields['mapper'] as $mapperPart) {
$importKeys[] = $mapperPart[0];
}
- $requiredFields = array(
- 'contact_id' => ts('Contact ID'),
- );
- foreach ($requiredFields as $field => $title) {
- if (!in_array($field, $importKeys)) {
- if (!isset($errors['_qf_default'])) {
- $errors['_qf_default'] = '';
- }
- $errors['_qf_default'] .= ts('Missing required field: %1', array(1 => $title));
+
+ // check either contact id or external identifier
+ if (!in_array('contact_id', $importKeys) && !in_array('external_identifier', $importKeys)) {
+ if (!isset($errors['_qf_default'])) {
+ $errors['_qf_default'] = '';
}
+ $errors['_qf_default'] .= ts('Missing required field: %1', array(1 => ts('Contact ID')));
}
}
$this->_fields = array_merge(array(
'do_not_import' => array('title' => ts('- do not import -')),
'contact_id' => array('title' => ts('Contact ID')),
+ 'external_identifier' => array('title' => ts('External Identifier')),
), $importableFields);
}
$session = CRM_Core_Session::singleton();
$dateType = $session->get('dateTypes');
- $formatted['id'] = $this->_params['contact_id'];
+ if (isset($this->_params['external_identifier']) && !isset($this->_params['contact_id'])) {
+ $checkCid = new CRM_Contact_DAO_Contact();
+ $checkCid->external_identifier = $this->_params['external_identifier'];
+ $checkCid->find(TRUE);
+ $formatted['id'] = $checkCid->id;
+ } else {
+ $formatted['id'] = $this->_params['contact_id'];
+ }
$setDateFields = array_intersect_key($this->_params, array_flip($this->_dateFields));
CRM_Contact_Import_Parser_Contact::formatCommonData($this->_params, $formatted, $formatted);