Minor consolidation on isTest()
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 23 Nov 2023 20:28:24 +0000 (09:28 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 23 Nov 2023 20:28:24 +0000 (09:28 +1300)
I think this makes sense as a publicly supported function we should consolidate in as many forms
as possible

CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/ContributionBase.php

index 19c02e2c636299658f88ca2f6c380dce78834212..c1bd8b931926bd0a1c823fffc27fb08de15391e9 100644 (file)
@@ -610,7 +610,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
    */
   private function buildMembershipBlock() {
     $cid = $this->_membershipContactID;
-    $isTest = (bool) ($this->getAction() & CRM_Core_Action::PREVIEW);
     $separateMembershipPayment = FALSE;
     $this->addOptionalQuickFormElement('auto_renew');
     if ($this->_membershipBlock) {
@@ -691,7 +690,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
                 ->addWhere('contact_id', '=', $cid)
                 ->addWhere('membership_type_id', '=', $memType['id'])
                 ->addWhere('status_id:name', 'NOT IN', ['Cancelled', 'Pending'])
-                ->addWhere('is_test', '=', (bool) $isTest)
+                ->addWhere('is_test', '=', $this->isTest())
                 ->addOrderBy('end_date', 'DESC')
                 ->execute()
                 ->first();
@@ -855,8 +854,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     ) {
 
       // appears to be unreachable - selectMembership never set...
-      $isTest = $self->_action & CRM_Core_Action::PREVIEW;
-      $lifeMember = CRM_Member_BAO_Membership::getAllContactMembership($self->_membershipContactID, $isTest, TRUE);
+      $lifeMember = CRM_Member_BAO_Membership::getAllContactMembership($self->_membershipContactID, $self->isTest(), TRUE);
 
       $membershipOrgDetails = CRM_Member_BAO_MembershipType::getAllMembershipTypes();
       $unallowedOrgs = [];
index 236cfde3974621179c2cce65e6194bd92e87c840..bc7c4e13c38c1344b9f713f8e7dee91c880630c5 100644 (file)
@@ -227,6 +227,17 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
     return $this->getPriceSetID() && CRM_Price_BAO_PriceSet::isQuickConfig($this->getPriceSetID());
   }
 
+  /**
+   * Is the form being submitted in test mode.
+   *
+   * @api this function is supported for external use.
+   *
+   * @return bool
+   */
+  public function isTest(): bool {
+    return (bool) ($this->getAction() & CRM_Core_Action::PREVIEW);
+  }
+
   /**
    * Get the price set for the contribution page.
    *