From da62deab175e1a01d8be67f4083fe8b98a965283 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 24 Nov 2023 09:28:24 +1300 Subject: [PATCH] Minor consolidation on isTest() 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 | 6 ++---- CRM/Contribute/Form/ContributionBase.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 19c02e2c63..c1bd8b9319 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -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 = []; diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 236cfde397..bc7c4e13c3 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -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. * -- 2.25.1