/**
* Function to set variables up before form is built
*
+ * @param $form
+ *
* @return void
* @access static
*/
* @return void
*/
static function buildQuickForm(&$form) {
- if ($form->_mode == 'live' && $form->_honor_block_is_active) {
+ if ($form->_mode == 'live' && !empty($form->_honor_block_is_active)) {
$ufJoinDAO = new CRM_Core_DAO_UFJoin();
$ufJoinDAO->module = 'soft_credit';
$ufJoinDAO->entity_id = $form->_id;
if ($ufJoinDAO->find(TRUE)) {
- $jsonData = json_decode($ufJoinDAO->module_data);
+ $jsonData = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($ufJoinDAO->module_data, TRUE);
if ($jsonData) {
- $form->assign('honor_block_title', $jsonData->soft_credit->honor_block_title);
- $form->assign('honor_block_text', $jsonData->soft_credit->honor_block_text);
+ foreach (array('honor_block_title', 'honor_block_text') as $name) {
+ $form->assign($name, $jsonData[$name]);
+ }
$softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
- $extraOption = array('onclick' => "enableHonorType();");
// radio button for Honor Type
- foreach ($jsonData->soft_credit->soft_credit_types as $value) {
- $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value, $extraOption);
+ foreach ($jsonData['soft_credit_types'] as $value) {
+ $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
}
- $form->addGroup($honorTypes, 'soft_credit_type_id', NULL);
+ $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
}
}
return $form;
if ($form->getAction() & CRM_Core_Action::UPDATE) {
$form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
}
- elseif ($form->_pledgeID) {
+ elseif (!empty($form->_pledgeID)) {
//Check and select most recent completed contrubtion and use it to retrieve
//soft-credit information to use as default for current pledge payment, CRM-13981
$pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID);
CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"),
array('id' => 'sct_default_id')
);
-
- // Tell tpl to hide soft credit field if contribution is linked directly to a PCP Page
- if (!empty($form->_values['pcp_made_through_id'])) {
- $form->assign('pcpLinked', 1);
- }
}
/**
* Function used to set defaults for soft credit block
*/
static function setDefaultValues(&$defaults, &$form) {
+ //Used to hide/unhide PCP and/or Soft-credit Panes
+ $noPCP = $noSoftCredit = TRUE;
if (!empty($form->_softCreditInfo['soft_credit'])) {
+ $noSoftCredit = FALSE;
foreach ($form->_softCreditInfo['soft_credit'] as $key => $value) {
$defaults["soft_credit_amount[$key]"] = CRM_Utils_Money::format($value['amount'], NULL, '%a');
$defaults["soft_credit_contact_id[$key]"] = $value['contact_id'];
$defaults["soft_credit_type[$key]"] = $value['soft_credit_type'];
}
}
- elseif (!empty($form->_softCreditInfo['pcp_id'])) {
+ if (!empty($form->_softCreditInfo['pcp_id'])) {
+ $noPCP = FALSE;
$pcpInfo = $form->_softCreditInfo;
$pcpId = CRM_Utils_Array::value('pcp_id', $pcpInfo);
$pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title');
$defaults['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcpInfo);
$defaults['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcpInfo);
}
+
+ $form->assign('noSoftCredit', $noSoftCredit);
+ $form->assign('noPCP', $noPCP);
}
/**
* global form rule
*
- * @param array $fields the input form values
+ * @param array $fields the input form values
+ *
+ * @param $errors
+ * @param $self
*
- * @return true if no errors, else array of errors
+ * @return array of errors
* @access public
* @static
*/