From c60b24f59dcbafa38f8e0ca9d9be86536578a6b9 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 23 Aug 2022 15:49:20 +1200 Subject: [PATCH] Deprecate getAvailableFields on parser class It really is a form layer function, called from one place on the forms and one on the unit tests --- CRM/Import/Forms.php | 21 ++++++++++++++++++++- CRM/Import/Parser.php | 4 +++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CRM/Import/Forms.php b/CRM/Import/Forms.php index 0efc526e67..d9112f233e 100644 --- a/CRM/Import/Forms.php +++ b/CRM/Import/Forms.php @@ -579,7 +579,26 @@ class CRM_Import_Forms extends CRM_Core_Form { * @throws \API_Exception */ protected function getAvailableFields(): array { - return $this->getParser()->getAvailableFields(); + $return = []; + foreach ($this->getFields() as $name => $field) { + if ($name === 'id' && $this->isSkipDuplicates()) { + // Duplicates are being skipped so id matching is not available. + continue; + } + $return[$name] = $field['html']['label'] ?? $field['title']; + } + return $return; + } + + /** + * Get the fields available for import selection. + * + * @return array + * e.g ['first_name' => 'First Name', 'last_name' => 'Last Name'.... + * + */ + protected function getFields(): array { + return $this->getParser()->getFieldsMetadata(); } /** diff --git a/CRM/Import/Parser.php b/CRM/Import/Parser.php index 0c867dc804..02a7ce57c1 100644 --- a/CRM/Import/Parser.php +++ b/CRM/Import/Parser.php @@ -319,6 +319,8 @@ abstract class CRM_Import_Parser implements UserJobInterface { * Once we have cleaned up the way the mapper is handled * we can ditch all the existing _construct parameters in favour * of just the userJobID - there are current open PRs towards this end. + * + * @deprecated */ public function getAvailableFields(): array { $this->setFieldMetadata(); @@ -1733,7 +1735,7 @@ abstract class CRM_Import_Parser implements UserJobInterface { * * @return array */ - protected function getFieldsMetadata() : array { + public function getFieldsMetadata() : array { if (empty($this->importableFieldsMetadata)) { unset($this->userJob); $this->setFieldMetadata(); -- 2.25.1