From f2f0c32156eece3b42e1cfd9f268156f8c579aad Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 18 Aug 2023 13:31:39 +1200 Subject: [PATCH] Pass in function values, rather than handling by form-name --- CRM/Contribute/Form/Contribution.php | 2 +- CRM/Member/Form/Membership.php | 2 +- CRM/Price/BAO/PriceSet.php | 15 +++------------ 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index b1f3a66511..8eeb434cf8 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -542,7 +542,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } $this->set('priceSetId', $this->_priceSetId); - CRM_Price_BAO_PriceSet::buildPriceSet($this); + CRM_Price_BAO_PriceSet::buildPriceSet($this, 'contribution', FALSE); // get only price set form elements. if ($getOnlyPriceSetElements) { diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 08ea8f2d63..c3e1daea7a 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -336,7 +336,7 @@ DESC limit 1"); } $this->set('priceSetId', $this->_priceSetId); - CRM_Price_BAO_PriceSet::buildPriceSet($this); + CRM_Price_BAO_PriceSet::buildPriceSet($this, 'membership', FALSE); $optionsMembershipTypes = []; foreach ($this->_priceSet['fields'] as $pField) { diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 3a1a4f642d..f7ca200819 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -793,23 +793,18 @@ WHERE id = %1"; * * @param CRM_Core_Form $form * @param string|null $component + * @param bool $validFieldsOnly * * @return void + * @throws \CRM_Core_Exception */ - public static function buildPriceSet(&$form, $component = NULL) { + public static function buildPriceSet(&$form, $component = NULL, $validFieldsOnly = TRUE) { $priceSetId = $form->get('priceSetId'); if (!$priceSetId) { return; } - $validFieldsOnly = TRUE; $className = CRM_Utils_System::getClassName($form); - if (in_array($className, [ - 'CRM_Contribute_Form_Contribution', - 'CRM_Member_Form_Membership', - ])) { - $validFieldsOnly = FALSE; - } $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly); $form->_priceSet = $priceSet[$priceSetId] ?? NULL; @@ -841,10 +836,6 @@ WHERE id = %1"; $form->_priceSet['id'] = $form->_priceSet['id'] ?? $priceSetId; $form->assign('priceSet', $form->_priceSet); - if ($className == 'CRM_Member_Form_Membership') { - $component = 'membership'; - } - if ($className == 'CRM_Contribute_Form_Contribution_Main') { $feeBlock = &$form->_values['fee']; } -- 2.25.1