[REF] move code into the function
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 21 Dec 2021 20:37:06 +0000 (09:37 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 21 Dec 2021 20:37:06 +0000 (09:37 +1300)
Within the if there is some code & then a function call. There doesn't seem
to be much reason for some of the code to be in the function & some
outside - this simplifies

CRM/Contribute/Form/Contribution/Confirm.php

index f57911b430750d5fa565e984d9d13b75c33631ad..7f4e62aec049e800bcb5d79df53ca0782e27da6e 100644 (file)
@@ -2331,27 +2331,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
 
     // store the fact that this is a membership and membership type is selected
     if ($this->isMembershipSelected($membershipParams)) {
-      if (!$this->_useForMember) {
-        $this->assign('membership_assign', TRUE);
-        $this->set('membershipTypeID', $this->_params['selectMembership']);
-      }
-
-      if ($this->_action & CRM_Core_Action::PREVIEW) {
-        $membershipParams['is_test'] = 1;
-      }
-      if ($this->_params['is_pay_later']) {
-        $membershipParams['is_pay_later'] = 1;
-      }
-
-      if (isset($this->_params['onbehalf_contact_id'])) {
-        $membershipParams['onbehalf_contact_id'] = $this->_params['onbehalf_contact_id'];
-      }
-      //inherit campaign from contribution page.
-      if (!array_key_exists('campaign_id', $membershipParams)) {
-        $membershipParams['campaign_id'] = $this->_values['campaign_id'] ?? NULL;
-      }
-
-      $this->_params = CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $membershipParams, TRUE);
       $this->doMembershipProcessing($contactID, $membershipParams, $premiumParams, $this->_lineItem);
     }
     else {
@@ -2453,6 +2432,28 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
    * @param array $formLineItems
    */
   protected function doMembershipProcessing($contactID, $membershipParams, $premiumParams, $formLineItems) {
+    if (!$this->_useForMember) {
+      $this->assign('membership_assign', TRUE);
+      $this->set('membershipTypeID', $this->_params['selectMembership']);
+    }
+
+    if ($this->_action & CRM_Core_Action::PREVIEW) {
+      $membershipParams['is_test'] = 1;
+    }
+    if ($this->_params['is_pay_later']) {
+      $membershipParams['is_pay_later'] = 1;
+    }
+
+    if (isset($this->_params['onbehalf_contact_id'])) {
+      $membershipParams['onbehalf_contact_id'] = $this->_params['onbehalf_contact_id'];
+    }
+    //inherit campaign from contribution page.
+    if (!array_key_exists('campaign_id', $membershipParams)) {
+      $membershipParams['campaign_id'] = $this->_values['campaign_id'] ?? NULL;
+    }
+
+    $this->_params = CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $membershipParams, TRUE);
+
     // This could be set by a hook.
     if (!empty($this->_params['installments'])) {
       $membershipParams['installments'] = $this->_params['installments'];