Fix button breakage on viewContribution
[civicrm-core.git] / CRM / Contribute / Form / UpdateSubscription.php
index e38baacc44e5543bc04f2e20cc02c8c2b248dfe2..a5772c74ce5b9ca59efd12ffbe17c73925cdc354 100644 (file)
@@ -151,10 +151,18 @@ class CRM_Contribute_Form_UpdateSubscription extends CRM_Contribute_Form_Contrib
     if (count($lineItems) > 1) {
       $amtAttr += ['readonly' => TRUE];
     }
-    $this->addMoney('amount', ts('Recurring Contribution Amount'), TRUE, $amtAttr,
+    $amountField = $this->addMoney('amount', ts('Recurring Contribution Amount'), TRUE, $amtAttr,
       TRUE, 'currency', $this->_subscriptionDetails->currency, TRUE
     );
 
+    // The amount on the recurring contribution should not be updated directly. If we update the amount using a template contribution the recurring contribution
+    //   will be updated automatically.
+    $paymentProcessorObj = Civi\Payment\System::singleton()->getById(CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorID($this->contributionRecurID));
+    $templateContribution = CRM_Contribute_BAO_ContributionRecur::getTemplateContribution($this->contributionRecurID);
+    if (!empty($templateContribution['id']) && $paymentProcessorObj->supportsEditRecurringContribution()) {
+      $amountField->freeze();
+    }
+
     $this->add('text', 'installments', ts('Number of Installments'), ['size' => 20], FALSE);
 
     if ($this->_donorEmail) {