diff --git a/ftoverride.php b/ftoverride.php index 9a987b8..bc908a8 100644 --- a/ftoverride.php +++ b/ftoverride.php @@ -240,6 +240,9 @@ function ftoverride_civicrm_buildForm($formName, &$form) { $submitValues = $form->_params; if (!empty($submitValues['designation'])) { $form->assign('contribution_designation', $submitValues['designation']); + if ($submitValues['designation'] == 'other_financial_type') { + $form->_params['contribution_note'] = $submitValues['designation_note']; + } } } @@ -260,6 +263,11 @@ function ftoverride_civicrm_buildForm($formName, &$form) { FALSE, ['class' => 'crm-select2'] ); + $form->add( + 'text', + 'designation_note', + '' + ); CRM_Core_Region::instance('page-body')->add(array( 'template' => 'CRM/Contribute/Form/ContributionMain/common.tpl', )); @@ -280,8 +288,12 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) { if ($op == 'create' && $objectName == 'Contribution' && !empty($params['contribution_page_id'])) { $designation = CRM_Core_Smarty::singleton()->get_template_vars('contribution_designation'); if (!empty($designation)) { - $params['financial_type_id'] = $designation; - CRM_Core_Smarty::singleton()->assign('contribution_designation', ''); + if ($designation == 'other_financial_type') { + // Ignore + } + else { + $params['financial_type_id'] = $designation; + } } } @@ -312,7 +324,7 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) { function ftoverride_civicrm_buildAmount($pageType, &$form, &$amount) { if (!empty($amount) && $form->_flagSubmitted) { $submitValues = $form->_submitValues; - if (!empty($submitValues['designation'])) { + if (!empty($submitValues['designation']) && $submitValues['designation'] != 'other_financial_type') { foreach ($amount as &$priceFields) { foreach ($priceFields['options'] as &$options) { $options['financial_type_id'] = $submitValues['designation']; @@ -338,6 +350,9 @@ function ftoverride_get_designation($pageId) { function ftoverride_get_financialType($action) { $financialTypes = []; CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $action); + if (empty($financialTypes)) { + return $financialTypes; + } $result = civicrm_api3('FinancialType', 'get', [ 'return' => ["description"], 'description' => ['!=' => ""], @@ -347,5 +362,5 @@ function ftoverride_get_financialType($action) { if (!empty($result['values'])) { $descFinancialType = array_column($result['values'], 'description', 'id'); } - return $descFinancialType + $financialTypes; + return $descFinancialType + $financialTypes + ['other_financial_type' => ts('Other')]; } diff --git a/templates/CRM/Contribute/Form/ContributionMain/common.tpl b/templates/CRM/Contribute/Form/ContributionMain/common.tpl index ca064c8..96bbed7 100644 --- a/templates/CRM/Contribute/Form/ContributionMain/common.tpl +++ b/templates/CRM/Contribute/Form/ContributionMain/common.tpl @@ -1,12 +1,27 @@