diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 706287757850..eb2979e4dd69 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -372,7 +372,7 @@ public function buildQuickForm() { // build price set form. $this->set('priceSetId', $this->_priceSetId); if (empty($this->_ccid)) { - CRM_Price_BAO_PriceSet::buildPriceSet($this); + CRM_Price_BAO_PriceSet::buildPriceSet($this, $this->getMainEntityType()); } if ($this->_values['is_monetary'] && $this->_values['is_recur'] && empty($this->_values['pledge_id']) diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 1b79b33b3d92..1d41e1ae54cf 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -1305,9 +1305,8 @@ protected function getMembershipBlock() { */ protected function isMembershipPriceSet(): bool { if ($this->_useForMember === NULL) { - if (CRM_Core_Component::isEnabled('CiviMember') && - (!$this->isQuickConfig() || !empty($this->_ccid)) && - (int) CRM_Core_Component::getComponentID('CiviMember') === (int) $this->order->getPriceSetMetadata()['extends']) { + if ($this->getMainEntityType() === 'membership' && + !$this->isQuickConfig()) { $this->_useForMember = 1; } else { @@ -1318,6 +1317,13 @@ protected function isMembershipPriceSet(): bool { return (bool) $this->_useForMember; } + public function getMainEntityType() { + if (CRM_Core_Component::isEnabled('CiviMember') && (int) CRM_Core_Component::getComponentID('CiviMember') === (int) $this->order->getPriceSetMetadata()['extends']) { + return 'membership'; + } + return 'contribution'; + } + /** * Should the membership block be displayed. * diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index e263fdf3dedb..d3dedcbbe14a 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -791,10 +791,11 @@ public static function getCachedPriceSetDetail($priceSetID) { * Build the price set form. * * @param CRM_Core_Form $form + * @param string|null $component * * @return void */ - public static function buildPriceSet(&$form) { + public static function buildPriceSet(&$form, $component = NULL) { $priceSetId = $form->get('priceSetId'); if (!$priceSetId) { return; @@ -847,23 +848,19 @@ public static function buildPriceSet(&$form) { $form->_priceSet['id'] = $form->_priceSet['id'] ?? $priceSetId; $form->assign('priceSet', $form->_priceSet); - $component = 'contribution'; if ($className == 'CRM_Member_Form_Membership') { $component = 'membership'; } if ($className == 'CRM_Contribute_Form_Contribution_Main') { $feeBlock = &$form->_values['fee']; - if (!empty($form->_useForMember)) { - $component = 'membership'; - } } else { $feeBlock = &$form->_priceSet['fields']; } // Call the buildAmount hook. - CRM_Utils_Hook::buildAmount($component, $form, $feeBlock); + CRM_Utils_Hook::buildAmount($component ?? 'contribution', $form, $feeBlock); self::addPriceFieldsToForm($form, $feeBlock, $validFieldsOnly, $className, $validPriceFieldIds); }