Skip to content
Snippets Groups Projects
Commit 78f0ee1b authored by colemanw's avatar colemanw
Browse files

Fix onBehalf required fields CRM-12149

parent 061a96be
No related branches found
No related tags found
No related merge requests found
...@@ -47,8 +47,8 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu ...@@ -47,8 +47,8 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
public $_relatedOrganizationFound; public $_relatedOrganizationFound;
public $_onBehalfRequired = 0; public $_onBehalfRequired = FALSE;
public $_onbehalf = 0; public $_onbehalf = FALSE;
public $_paymentProcessors; public $_paymentProcessors;
protected $_defaults; protected $_defaults;
...@@ -99,28 +99,43 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu ...@@ -99,28 +99,43 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
$this->assign('mainDisplay', $mainDisplay); $this->assign('mainDisplay', $mainDisplay);
} }
// Possible values for 'is_for_organization':
// * 0 - org profile disabled
// * 1 - org profile optional
// * 2 - org profile required
$this->_onbehalf = FALSE; $this->_onbehalf = FALSE;
if (CRM_Utils_Array::value('is_for_organization', $this->_values)) { if (!empty($this->_values['is_for_organization'])) {
$this->_onbehalf = TRUE; if ($this->_values['is_for_organization'] == 2) {
CRM_Contribute_Form_Contribution_OnBehalfOf::preProcess($this); $this->_onBehalfRequired = TRUE;
}
// Add organization profile if 1 of the following are true:
// If the org profile is required
if ($this->_onBehalfRequired ||
// Or we are building the form for the first time
empty($_POST) ||
// Or the user has submitted the form and checked the "On Behalf" checkbox
!empty($_POST['is_for_organization'])
) {
$this->_onbehalf = TRUE;
CRM_Contribute_Form_Contribution_OnBehalfOf::preProcess($this);
}
} }
$this->assign('onBehalfRequired', $this->_onBehalfRequired);
if (CRM_Utils_Array::value('id', $this->_pcpInfo) && if (!empty($this->_pcpInfo['id']) && !empty($this->_pcpInfo['intro_text'])) {
CRM_Utils_Array::value('intro_text', $this->_pcpInfo)
) {
$this->assign('intro_text', $this->_pcpInfo['intro_text']); $this->assign('intro_text', $this->_pcpInfo['intro_text']);
} }
elseif (CRM_Utils_Array::value('intro_text', $this->_values)) { elseif (!empty($this->_values['intro_text'])) {
$this->assign('intro_text', $this->_values['intro_text']); $this->assign('intro_text', $this->_values['intro_text']);
} }
$qParams = "reset=1&id={$this->_id}"; $qParams = "reset=1&id={$this->_id}";
if ( $pcpId = CRM_Utils_Array::value( 'pcp_id', $this->_pcpInfo ) ) { if ($pcpId = CRM_Utils_Array::value('pcp_id', $this->_pcpInfo)) {
$qParams .= "&pcpId={$pcpId}"; $qParams .= "&pcpId={$pcpId}";
} }
$this->assign( 'qParams' , $qParams ); $this->assign('qParams', $qParams);
if (CRM_Utils_Array::value('footer_text', $this->_values)) { if (!empty($this->_values['footer_text'])) {
$this->assign('footer_text', $this->_values['footer_text']); $this->assign('footer_text', $this->_values['footer_text']);
} }
...@@ -167,10 +182,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu ...@@ -167,10 +182,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
} }
function setDefaultValues() { function setDefaultValues() {
if ($this->_onbehalf) {
return;
}
// check if the user is registered and we have a contact ID // check if the user is registered and we have a contact ID
$contactID = $this->_userID; $contactID = $this->_userID;
...@@ -373,10 +384,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu ...@@ -373,10 +384,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
} }
$config = CRM_Core_Config::singleton(); $config = CRM_Core_Config::singleton();
if (CRM_Utils_Array::value('is_for_organization', $this->_values) == 2) {
$this->assign('onBehalfRequired', TRUE);
$this->_onBehalfRequired = 1;
}
if ($this->_onbehalf) { if ($this->_onbehalf) {
CRM_Contribute_Form_Contribution_OnBehalfOf::buildQuickForm($this); CRM_Contribute_Form_Contribution_OnBehalfOf::buildQuickForm($this);
} }
...@@ -629,16 +637,12 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu ...@@ -629,16 +637,12 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
CRM_Core_BAO_Location::getValues($entityBlock, $this->_defaults); CRM_Core_BAO_Location::getValues($entityBlock, $this->_defaults);
} }
if ($this->_values['is_for_organization'] != 2) { if (!$this->_onBehalfRequired) {
$this->addElement('checkbox', 'is_for_organization', $this->addElement('checkbox', 'is_for_organization',
$this->_values['for_organization'], $this->_values['for_organization'],
NULL, array('onclick' => "showOnBehalf( );") NULL, array('onclick' => "showOnBehalf( );")
); );
} }
else {
$this->assign('onBehalfRequired', TRUE);
$this->_onBehalfRequired = 1;
}
$this->assign('is_for_organization', TRUE); $this->assign('is_for_organization', TRUE);
$this->assign('urlPath', 'civicrm/contribute/transact'); $this->assign('urlPath', 'civicrm/contribute/transact');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment