From 92ff8582d79b5788ecff15a48939a49a5959f23c Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 7 Sep 2022 11:41:03 +1200 Subject: [PATCH] Adjust contribution metadata to filter at display not load --- CRM/Contribute/Import/Form/MapField.php | 12 ++++++++++++ CRM/Import/Forms.php | 17 +++++++++++++++++ CRM/Import/Parser.php | 12 +++++------- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/CRM/Contribute/Import/Form/MapField.php b/CRM/Contribute/Import/Form/MapField.php index 8188e3cd5a..4222dba205 100644 --- a/CRM/Contribute/Import/Form/MapField.php +++ b/CRM/Contribute/Import/Form/MapField.php @@ -71,6 +71,18 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField { $this->assign('highlightedFields', $highlightedFields); } + /** + * Should contact fields be filtered which determining fields to show. + * + * This applies to Contribution import as we put all contact fields in the metadata + * but only present those used for a match - but will permit create via LeXIM. + * + * @return bool + */ + protected function isFilterContactFields() : bool { + return TRUE; + } + /** * Build the form object. * diff --git a/CRM/Import/Forms.php b/CRM/Import/Forms.php index da50cf3f69..3fdea35450 100644 --- a/CRM/Import/Forms.php +++ b/CRM/Import/Forms.php @@ -585,11 +585,28 @@ class CRM_Import_Forms extends CRM_Core_Form { // Duplicates are being skipped so id matching is not available. continue; } + if (($field['entity'] ?? '') === 'Contact' && $this->isFilterContactFields() && empty($field['match_rule'])) { + // Filter out metadata that is intended for create & update - this is not available in the quick-form + // but is now loaded in the Parser for the LexIM variant. + continue; + } $return[$name] = $field['html']['label'] ?? $field['title']; } return $return; } + /** + * Should contact fields be filtered which determining fields to show. + * + * This applies to Contribution import as we put all contact fields in the metadata + * but only present those used for a match - but will permit create via LeXIM. + * + * @return bool + */ + protected function isFilterContactFields() : bool { + return FALSE; + } + /** * Get the fields available for import selection. * diff --git a/CRM/Import/Parser.php b/CRM/Import/Parser.php index 63127ac073..1824f2501a 100644 --- a/CRM/Import/Parser.php +++ b/CRM/Import/Parser.php @@ -324,19 +324,17 @@ abstract class CRM_Import_Parser implements UserJobInterface { $contactFields = $this->getAllContactFields(''); $dedupeFields = $this->getDedupeFields($contactType); - $contactFieldsForContactLookup = []; foreach ($dedupeFields as $fieldName => $dedupeField) { if (!isset($contactFields[$fieldName])) { continue; } - $contactFieldsForContactLookup[$fieldName] = $contactFields[$fieldName]; - $contactFieldsForContactLookup[$fieldName]['title'] . ' ' . ts('(match to contact)'); - $contactFieldsForContactLookup[$fieldName]['entity'] = 'Contact'; + $contactFields[$fieldName]['title'] . ' ' . ts('(match to contact)'); + $contactFields[$fieldName]['match_rule'] = $this->getDefaultRuleForContactType($contactType); } - $contactFieldsForContactLookup['external_identifier'] = $contactFields['external_identifier']; - $contactFieldsForContactLookup['external_identifier']['title'] = $contactFields['external_identifier']['title'] . ' ' . ts('(match to contact)'); - return $contactFieldsForContactLookup; + $contactFields['external_identifier']['title'] .= ts('(match to contact)'); + $contactFields['external_identifier']['match_rule'] = '*'; + return $contactFields; } /** -- 2.25.1