[REF] Minor code simplification - extract getHighlightedFields
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 18 Mar 2023 23:09:57 +0000 (12:09 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 18 Mar 2023 23:11:20 +0000 (12:11 +1300)
CRM/Contribute/Import/Form/MapField.php

index abc42a05b2be35df6f626ac4bfc384fd7e05dc5d..6721a4f83691f1cb29df4543b7e5aa6051e91374 100644 (file)
  */
 class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField {
 
-  /**
-   * Set variables up before form is built.
-   */
-  public function preProcess() {
-    parent::preProcess();
-
-    $highlightedFields = ['financial_type_id', 'total_amount'];
-    //CRM-2219 removing other required fields since for updation only
-    //invoice id or trxn id or contribution id is required.
-    if ($this->isUpdateExisting()) {
-      //modify field title only for update mode. CRM-3245
-      foreach ([
-        'contribution_id',
-        'invoice_id',
-        'trxn_id',
-      ] as $key) {
-        $highlightedFields[] = $key;
-      }
-    }
-    elseif ($this->isSkipExisting()) {
-      $highlightedFieldsArray = [
-        'contribution_contact_id',
-        'email',
-        'first_name',
-        'last_name',
-        'external_identifier',
-      ];
-      foreach ($highlightedFieldsArray as $name) {
-        $highlightedFields[] = $name;
-      }
-    }
-
-    $this->assign('highlightedFields', $highlightedFields);
-  }
-
   /**
    * Should contact fields be filtered which determining fields to show.
    *
@@ -267,4 +232,32 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField {
     return NULL;
   }
 
+  /**
+   * @return string[]
+   */
+  protected function getHighlightedFields(): array {
+    $highlightedFields = ['financial_type_id', 'total_amount'];
+    //CRM-2219 removing other required fields since for updating only
+    //invoice id or trxn id or contribution id is required.
+    if ($this->isUpdateExisting()) {
+      //modify field title only for update mode. CRM-3245
+      foreach (['contribution_id', 'invoice_id', 'trxn_id'] as $key) {
+        $highlightedFields[] = $key;
+      }
+    }
+    elseif ($this->isSkipExisting()) {
+      $highlightedFieldsArray = [
+        'contribution_contact_id',
+        'email',
+        'first_name',
+        'last_name',
+        'external_identifier',
+      ];
+      foreach ($highlightedFieldsArray as $name) {
+        $highlightedFields[] = $name;
+      }
+    }
+    return $highlightedFields;
+  }
+
 }