Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show secondary fields (eg location for address fields) when setting #14

Merged
merged 1 commit into from
May 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions CRM/Contact/Import/Form/MapField.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,24 +304,23 @@ public function buildQuickForm() {
// do array search first to see if has mapped key
$columnKey = array_search($this->_columnNames[$i], $this->getFieldTitles());
if (isset($this->_fieldUsed[$columnKey])) {
$defaults["mapper[$i]"] = [$columnKey];
$this->_fieldUsed[$key] = TRUE;
$defaults["mapper[$i]"] = $this->createMapperDefault($columnKey, $sel2, $sel3);
$this->_fieldUsed[$columnKey] = TRUE;
}
else {
// Infer the default from the column names if we have them
$defaults["mapper[$i]"] = [
$defaults["mapper[$i]"] = $this->createMapperDefault(
$this->defaultFromColumnName($this->_columnNames[$i]),
0,
];
$sel2, $sel3
);
}
}
else {
// Otherwise guess the default from the form of the data
$defaults["mapper[$i]"] = [
$defaults["mapper[$i]"] = $this->createMapperDefault(
$this->defaultFromData($this->getDataPatterns(), $i),
// $defaultLocationType->id
0,
];
$sel2, $sel3
);
}
}
$sel->setOptions([$sel1, $sel2, $sel3, $sel4]);
Expand Down Expand Up @@ -614,12 +613,38 @@ protected function assignJsToHideUnusedFields(array $defaults): void {
foreach ([1, 2, 3] as $columnNumber) {
if (empty($mapperValues[$columnNumber])) {
$rowNumber = str_replace('mapper[', '', substr($row, 0, -1));
$js[] = "cj('#mapper_{$rowNumber}_{$columnNumber}').hide();";
$js[] = "CRM.\$('#mapper_{$rowNumber}_{$columnNumber}').hide();";
}
}
}
$js[] = "</script>\n";
$this->assign('initHideBoxes', implode("\n", $js));
}

/**
* Create the defaults for mapper fields.
*
* Some fields need a second or third value. These are extracted from
* $sel2, $sel3 - the select option lists.
*
* @param string $key
* @param array $sel2
* @param array $sel3
*
* @return array
*/
protected function createMapperDefault($key, $sel2, $sel3): array {
$def = [$key];
if (!empty($sel2[$key]) && is_array($sel2[$key])) {
reset($sel2[$key]);
$subkey=key($sel2[$key]);
$def[] = $subkey;
if (!empty($sel3[$key][$subkey]) && is_array($sel3[$key][$subkey])) {
reset($sel3[$key][$subkey]);
$def[] = key($sel3[$key][$subkey]);
}
}
return $def;
}

}