From 8452c60b016cc7bb8fc968789953ddeb1537b9d8 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 8 Sep 2022 23:53:59 +1200 Subject: [PATCH] Move header handling to the Form layer in import --- CRM/Contact/Import/MetadataTrait.php | 3 +++ CRM/Contribute/Import/Parser/Contribution.php | 3 ++- CRM/Import/Forms.php | 15 ++++++++++++++- CRM/Import/Parser.php | 3 +++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/Import/MetadataTrait.php b/CRM/Contact/Import/MetadataTrait.php index 19db539ed8..132782496b 100644 --- a/CRM/Contact/Import/MetadataTrait.php +++ b/CRM/Contact/Import/MetadataTrait.php @@ -79,6 +79,9 @@ trait CRM_Contact_Import_MetadataTrait { /** * Get an array of header patterns for importable keys. * + * We should do this work on the form layer. + * + * @deprecated * @return array */ public function getHeaderPatterns(): array { diff --git a/CRM/Contribute/Import/Parser/Contribution.php b/CRM/Contribute/Import/Parser/Contribution.php index e7853408e8..d3b9913cd8 100644 --- a/CRM/Contribute/Import/Parser/Contribution.php +++ b/CRM/Contribute/Import/Parser/Contribution.php @@ -637,7 +637,8 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Import_Parser { */ public function getMappingFieldFromMapperInput(array $fieldMapping, int $mappingID, int $columnNumber): array { return [ - 'name' => $fieldMapping[0], + // The double __ is a quickform hack - the 'real' name is dotted - eg. 'soft_credit.contact.id' + 'name' => str_replace('__', '.', $fieldMapping[0]), 'mapping_id' => $mappingID, 'column_number' => $columnNumber, // The name of the field to match the soft credit on is (crazily) diff --git a/CRM/Import/Forms.php b/CRM/Import/Forms.php index 3fdea35450..630ef38e24 100644 --- a/CRM/Import/Forms.php +++ b/CRM/Import/Forms.php @@ -590,6 +590,9 @@ class CRM_Import_Forms extends CRM_Core_Form { // but is now loaded in the Parser for the LexIM variant. continue; } + // Swap out dots for double underscores so as not to break the quick form js. + // We swap this back on postProcess. + $name = str_replace('.', '__', $name); $return[$name] = $field['html']['label'] ?? $field['title']; } return $return; @@ -702,7 +705,17 @@ class CRM_Import_Forms extends CRM_Core_Form { * @return array */ public function getHeaderPatterns(): array { - return $this->getParser()->getHeaderPatterns(); + $headerPatterns = []; + foreach ($this->getFields() as $name => $field) { + if (empty($field['headerPattern']) || $field['headerPattern'] === '//') { + continue; + } + // Swap out dots for double underscores so as not to break the quick form js. + // The parser class undoes this when looking up the field. + $name = str_replace('.', '__', $name); + $headerPatterns[$name] = $field['headerPattern']; + } + return $headerPatterns; } /** diff --git a/CRM/Import/Parser.php b/CRM/Import/Parser.php index 64a7558fca..08dda9da2a 100644 --- a/CRM/Import/Parser.php +++ b/CRM/Import/Parser.php @@ -517,6 +517,9 @@ abstract class CRM_Import_Parser implements UserJobInterface { } /** + * The form can do it's own work now... + * + * @deprecated * @return array */ public function getHeaderPatterns(): array { -- 2.25.1