+ $fields = civicrm_api3('MappingField', 'get', [
+ 'mapping_id' => $this->getMappingID(),
+ 'options' => ['limit' => 0],
+ ])['values'];
+ foreach ($fields as $index => $field) {
+ $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.
+ *
+ * This is preserved as a copy the upgrade script can use - since the
+ * upgrade allows the other to be 'fixed'.
+ *
+ * @throws \CiviCRM_API3_Exception
+ */
+ protected function legacyLoadSavedMapping() {