/**
* Build the form object.
+ *
+ * @throws \CiviCRM_API3_Exception
*/
public function buildQuickForm() {
// To save the current mappings.
$savedMapping = $this->get('savedMapping');
// Mapping is to be loaded from database.
- list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingRelation) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping);
-
- // Get loaded Mapping Fields.
- $mappingName = CRM_Utils_Array::value('1', $mappingName);
- $mappingContactType = CRM_Utils_Array::value('1', $mappingContactType);
- $mappingLocation = CRM_Utils_Array::value('1', $mappingLocation);
- $mappingPhoneType = CRM_Utils_Array::value('1', $mappingPhoneType);
- $mappingRelation = CRM_Utils_Array::value('1', $mappingRelation);
+ // Get an array of the name values for mapping fields associated with this mapping_id.
+ $mappingName = CRM_Core_BAO_Mapping::getMappingFieldValues($savedMapping, 'name');
$this->assign('loadedMapping', $savedMapping);
$this->set('loadedMapping', $savedMapping);
];
}
+ /**
+ * Get un-indexed array of the field values for the given mapping id.
+ *
+ * For example if passing a mapping ID & name the returned array would look like
+ * ['First field name', 'second field name']
+ *
+ * @param int $mappingID
+ * @param string $fieldName
+ *
+ * @return array
+ * @throws \CiviCRM_API3_Exception
+ */
+ public static function getMappingFieldValues($mappingID, $fieldName) {
+ return array_merge(CRM_Utils_Array::collect($fieldName, civicrm_api3('MappingField', 'get', ['mapping_id' => $mappingID, 'return' => $fieldName])['values']));
+ }
+
/**
* Check Duplicate Mapping Name.
*