Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract getMembershipBlock #25238

Merged
merged 1 commit into from
Jan 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,27 +373,6 @@ public function preProcess() {
}
}

//check if Membership Block is enabled, if Membership Fields are included in profile
//get membership section for this contribution page
$this->_membershipBlock = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
$this->set('membershipBlock', $this->_membershipBlock);

if (!empty($this->_values['custom_pre_id'])) {
$preProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_pre_id']);
}

if (!empty($this->_values['custom_post_id'])) {
$postProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_post_id']);
}

if (((isset($postProfileType) && $postProfileType === 'Membership') ||
(isset($preProfileType) && $preProfileType === 'Membership')
) &&
!$this->_membershipBlock['is_active']
) {
CRM_Core_Error::statusBounce(ts('This page includes a Profile with Membership fields - but the Membership Block is NOT enabled. Please notify the site administrator.'));
}

$pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id);

if ($pledgeBlock) {
Expand All @@ -420,6 +399,7 @@ public function preProcess() {
$this->set('values', $this->_values);
$this->set('fields', $this->_fields);
}
$this->set('membershipBlock', $this->getMembershipBlock());

// Handle PCP
$pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this);
Expand All @@ -445,9 +425,7 @@ public function preProcess() {
$this->assign('pledgeBlock', TRUE);
}

// check if one of the (amount , membership) blocks is active or not.
$this->_membershipBlock = $this->get('membershipBlock');

// @todo - move this check to `getMembershipBlock`
if (!$this->isFormSupportsNonMembershipContributions() &&
!$this->_membershipBlock['is_active'] &&
!$this->_priceSetId
Expand Down Expand Up @@ -1286,4 +1264,29 @@ public function isFormSupportsNonMembershipContributions(): bool {
return (bool) ($this->_values['amount_block_is_active'] ?? FALSE);
}

/**
* Get the membership block configured for the page, fetching if needed.
*
* The membership block is configured memberships are available to purchase via
* a quick-config price set.
*
* @return array|false
*/
protected function getMembershipBlock() {
if (!isset($this->_membershipBlock)) {
//check if Membership Block is enabled, if Membership Fields are included in profile
//get membership section for this contribution page
$this->_membershipBlock = CRM_Member_BAO_Membership::getMembershipBlock($this->_id) ?? FALSE;
$preProfileType = empty($this->_values['custom_pre_id']) ? NULL : CRM_Core_BAO_UFField::getProfileType($this->_values['custom_pre_id']);
$postProfileType = empty($this->_values['custom_post_id']) ? NULL : CRM_Core_BAO_UFField::getProfileType($this->_values['custom_post_id']);

if ((($postProfileType === 'Membership') || ($preProfileType === 'Membership')) &&
!$this->_membershipBlock['is_active']
) {
CRM_Core_Error::statusBounce(ts('This page includes a Profile with Membership fields - but the Membership Block is NOT enabled. Please notify the site administrator.'));
}
}
return $this->_membershipBlock;
}

}