for ($i = 0; $i < $this->_columnCount; $i++) {
$sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL);
- if ($this->get('savedMapping')) {
- list($defaults, $js) = $this->loadSavedMapping($processor, $i, $defaults, $js, $hasColumnNames);
+ if ($this->get('savedMapping') && $processor->getFieldName($i)) {
+ $defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i);
+ $js .= $processor->getQuickFormJSForField($i);
}
else {
$js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n";
return $saveMappingFields->mapping_id;
}
- /**
- * @param \CRM_Import_ImportProcessor $processor
- * @param $mappingName
- * @param int $i
- * @param array $defaults
- * @param string $js
- * @param bool $hasColumnNames
- *
- * @return array
- * @throws \CiviCRM_API3_Exception
- */
- public function loadSavedMapping($processor, $i, $defaults, $js, $hasColumnNames) {
- $formName = $processor->getFormName();
- if ($processor->getFieldName($i)) {
- $defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i);
- $js .= $processor->getQuickFormJSForField($i);
- }
- else {
- // this load section to help mapping if we ran out of saved columns when doing Load Mapping
- $js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n";
-
- if ($hasColumnNames) {
- $defaults["mapper[$i]"] = [$this->defaultFromColumnName($this->_columnNames[$i])];
- }
- else {
- $defaults["mapper[$i]"] = [$this->defaultFromData($this->getDataPatterns(), $i)];
- }
- }
- return [$defaults, $js];
- }
-
}
$mapping = $this->callAPISuccess('Mapping', 'create', ['name' => 'my test']);
$this->callAPISuccess('MappingField', 'create', array_merge(['mapping_id' => $mapping['id']], $fieldSpec));
- $result = $this->loadSavedMapping($this->form, $mapping['id'], $fieldSpec['column_number']);
+ $result = $this->loadSavedMapping($mapping['id'], $fieldSpec['column_number']);
$this->assertEquals($expectedJS, $result['js']);
$this->assertEquals($expectedDefaults, $result['defaults']);
}
*
* @throws \CiviCRM_API3_Exception
*/
- protected function loadSavedMapping($form, $mappingID, $columnNumber) {
- $defaults = [];
-
- $js = '';
- $hasColumnNames = TRUE;
+ protected function loadSavedMapping($mappingID, $columnNumber) {
$processor = new CRM_Import_ImportProcessor();
$processor->setMappingID($mappingID);
$processor->setFormName('document.forms.MapField');
$processor->setMetadata($this->getContactImportMetadata());
$processor->setContactTypeByConstant(CRM_Import_Parser::CONTACT_INDIVIDUAL);
- $return = $form->loadSavedMapping($processor, $columnNumber, $defaults, $js, $hasColumnNames);
- return ['defaults' => $return[0], 'js' => $return[1]];
+ $defaults = [];
+ $defaults["mapper[$columnNumber]"] = $processor->getSavedQuickformDefaultsForColumn($columnNumber);
+ $js = $processor->getQuickFormJSForField($columnNumber);
+
+ return ['defaults' => $defaults, 'js' => $js];
}
/**