'options' => ['limit' => 0],
])['values'];
foreach ($fields as $index => $field) {
- $fieldSpec = $this->getMetadata()[$fields[$index]['name']];
+ $fieldSpec = $this->getFieldMetadata($field['name']);
$fields[$index]['label'] = $fieldSpec['title'];
if (empty($field['location_type_id']) && !empty($fieldSpec['hasLocationType'])) {
$fields[$index]['location_type_id'] = 'Primary';
$this->mappingFields = $this->rekeyBySortedColumnNumbers($fields);
}
+ /**
+ * Get the metadata for the field.
+ *
+ * @param string $fieldName
+ *
+ * @return array
+ */
+ protected function getFieldMetadata(string $fieldName): array {
+ return $this->getMetadata()[$fieldName] ?? CRM_Contact_BAO_Contact::importableFields('All')[$fieldName];
+ }
+
/**
* Load the mapping from the database into the pre-5.50 format.
*
return !empty($this->getValidRelationships()[$key]);
}
- /**
- * Get the relevant js for quickform.
- *
- * @param int $column
- *
- * @return string
- * @throws \CiviCRM_API3_Exception
- */
- public function getQuickFormJSForField($column) {
- $columnNumbersToHide = [];
- if ($this->getFieldName($column) === 'do_not_import') {
- $columnNumbersToHide = [1, 2, 3];
- }
- elseif ($this->getRelationshipKey($column)) {
- if (!$this->getWebsiteTypeID($column) && !$this->getLocationTypeID($column)) {
- $columnNumbersToHide[] = 2;
- }
- if (!$this->getFieldName($column)) {
- $columnNumbersToHide[] = 1;
- }
- if (!$this->getPhoneOrIMTypeID($column)) {
- $columnNumbersToHide[] = 3;
- }
- }
- else {
- if (!$this->getLocationTypeID($column) && !$this->getWebsiteTypeID($column)) {
- $columnNumbersToHide[] = 1;
- }
- if (!$this->getPhoneOrIMTypeID($column)) {
- $columnNumbersToHide[] = 2;
- }
- $columnNumbersToHide[] = 3;
- }
-
- $jsClauses = [];
- foreach ($columnNumbersToHide as $columnNumber) {
- $jsClauses[] = $this->getFormName() . "['mapper[$column][" . $columnNumber . "]'].style.display = 'none';";
- }
- return empty($jsClauses) ? '' : implode("\n", $jsClauses) . "\n";
- }
-
/**
* Get the defaults for the column from the saved mapping.
*
* @throws \CiviCRM_API3_Exception
*/
public function getSavedQuickformDefaultsForColumn($column) {
+ $fieldMapping = [];
+
+ // $sel1 is either unmapped, a relationship or a target field.
if ($this->getFieldName($column) === 'do_not_import') {
- return [];
+ return $fieldMapping;
}
+
if ($this->getValidRelationshipKey($column)) {
- if ($this->getWebsiteTypeID($column)) {
- return [$this->getValidRelationshipKey($column), $this->getFieldName($column), $this->getWebsiteTypeID($column)];
- }
- return [$this->getValidRelationshipKey($column), $this->getFieldName($column), $this->getLocationTypeID($column), $this->getPhoneOrIMTypeID($column)];
+ $fieldMapping[] = $this->getValidRelationshipKey($column);
}
+
+ // $sel1
+ $fieldMapping[] = $this->getFieldName($column);
+
+ // $sel2
if ($this->getWebsiteTypeID($column)) {
- return [$this->getFieldName($column), $this->getWebsiteTypeID($column)];
+ $fieldMapping[] = $this->getWebsiteTypeID($column);
+ }
+ elseif ($this->getLocationTypeID($column)) {
+ $fieldMapping[] = $this->getLocationTypeID($column);
+ }
+
+ // $sel3
+ if ($this->getPhoneOrIMTypeID($column)) {
+ $fieldMapping[] = $this->getPhoneOrIMTypeID($column);
}
- return [(string) $this->getFieldName($column), $this->getLocationTypeID($column), $this->getPhoneOrIMTypeID($column)];
+ return $fieldMapping;
}
/**