|
|
|
@ -197,8 +197,17 @@ function ftoverride_civicrm_entityTypes(&$entityTypes) {
|
|
|
|
|
*/
|
|
|
|
|
function ftoverride_civicrm_buildForm($formName, &$form) {
|
|
|
|
|
if ('CRM_Contribute_Form_ContributionPage_Settings' == $formName) {
|
|
|
|
|
$financialTypes = [];
|
|
|
|
|
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $form->getVar('_action'));
|
|
|
|
|
$showElement = TRUE;
|
|
|
|
|
if ($form->getVar('_id')) {
|
|
|
|
|
$snippet = CRM_Utils_Array::value('snippet', $_GET);
|
|
|
|
|
if (empty($snippet)) {
|
|
|
|
|
$showElement = FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form->assign('showElement', $showElement);
|
|
|
|
|
$financialTypes = ftoverride_get_financialType($form->getVar('_action'));
|
|
|
|
|
$form->add('hidden', 'hidden_designation');
|
|
|
|
|
$form->add(
|
|
|
|
|
'select',
|
|
|
|
|
'designation',
|
|
|
|
@ -214,13 +223,17 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
|
|
|
|
|
CRM_Core_Region::instance('page-body')->add(array(
|
|
|
|
|
'template' => 'CRM/Contribute/Form/ContributionPage/common.tpl',
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
if ($form->getVar('_id')) {
|
|
|
|
|
try {
|
|
|
|
|
$designations = ftoverride_get_designation($form->getVar('_id'));
|
|
|
|
|
if (empty($designations)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$form->setDefaults(['designation' => $designations]);
|
|
|
|
|
$form->setDefaults([
|
|
|
|
|
'designation' => $designations,
|
|
|
|
|
'hidden_designation' => implode(',', $designations),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
|
|
|
|
// Ignore
|
|
|
|
@ -228,6 +241,16 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ('CRM_Contribute_Form_Contribution_Confirm' == $formName && $form->_flagSubmitted) {
|
|
|
|
|
$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'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ('CRM_Contribute_Form_Contribution_Main' == $formName) {
|
|
|
|
|
try {
|
|
|
|
|
$designations = ftoverride_get_designation($form->_id);
|
|
|
|
@ -235,18 +258,28 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$financialTypes = [];
|
|
|
|
|
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $form->getVar('_action'));
|
|
|
|
|
$financialTypes = ftoverride_get_financialType($form->getVar('_action'));
|
|
|
|
|
$designations = array_flip($designations);
|
|
|
|
|
$financialTypes = array_intersect_key($financialTypes, $designations);
|
|
|
|
|
foreach($designations as $id => &$label) {
|
|
|
|
|
$label = $financialTypes[$id];
|
|
|
|
|
}
|
|
|
|
|
$form->add(
|
|
|
|
|
'select',
|
|
|
|
|
'designation',
|
|
|
|
|
ts('Designation'),
|
|
|
|
|
['' => ts('- select -')] + $financialTypes,
|
|
|
|
|
['' => ts('- select -')] + $designations,
|
|
|
|
|
FALSE,
|
|
|
|
|
['class' => 'crm-select2']
|
|
|
|
|
);
|
|
|
|
|
$form->add(
|
|
|
|
|
'text',
|
|
|
|
|
'designation_note',
|
|
|
|
|
''
|
|
|
|
|
);
|
|
|
|
|
reset($designations);
|
|
|
|
|
$form->setDefaults([
|
|
|
|
|
'designation' => key($designations),
|
|
|
|
|
]);
|
|
|
|
|
CRM_Core_Region::instance('page-body')->add(array(
|
|
|
|
|
'template' => 'CRM/Contribute/Form/ContributionMain/common.tpl',
|
|
|
|
|
));
|
|
|
|
@ -264,9 +297,21 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
|
|
|
|
|
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm
|
|
|
|
|
*/
|
|
|
|
|
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)) {
|
|
|
|
|
if ($designation == 'other_financial_type') {
|
|
|
|
|
// Ignore
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$params['financial_type_id'] = $designation;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (in_array($op, ['create', 'edit'])
|
|
|
|
|
&& $objectName == 'ContributionPage'
|
|
|
|
|
&& !empty($params['designation'])
|
|
|
|
|
&& isset($params['designation'])
|
|
|
|
|
) {
|
|
|
|
|
if ($id) {
|
|
|
|
|
$params['id'] = $id;
|
|
|
|
@ -276,13 +321,29 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) {
|
|
|
|
|
'custom_group_id' => "ft_override",
|
|
|
|
|
'name' => "ft_override_designation",
|
|
|
|
|
]);
|
|
|
|
|
$params["custom_{$customFieldId}"] = $params['designation'];
|
|
|
|
|
unset($params['designation']);
|
|
|
|
|
$params["custom_{$customFieldId}"] = explode(',', $params['hidden_designation']);
|
|
|
|
|
unset($params['designation'], $params['hidden_designation']);
|
|
|
|
|
$contributionPage = civicrm_api3('ContributionPage', 'create', $params);
|
|
|
|
|
$params = ['id' => $contributionPage['id']];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implements hook_civicrm_validateForm().
|
|
|
|
|
*
|
|
|
|
|
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_validateForm
|
|
|
|
|
*/
|
|
|
|
|
function ftoverride_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) {
|
|
|
|
|
if ('CRM_Contribute_Form_Contribution_Main' == $formName) {
|
|
|
|
|
if (!empty($fields['designation'])
|
|
|
|
|
&& $fields['designation'] == 'other_financial_type'
|
|
|
|
|
&& empty($fields['designation_note'])
|
|
|
|
|
) {
|
|
|
|
|
$errors['designation_note'] = ts('Please provide other information about designation.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implements hook_civicrm_buildAmount().
|
|
|
|
|
*
|
|
|
|
@ -291,7 +352,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'];
|
|
|
|
@ -313,3 +374,21 @@ function ftoverride_get_designation($pageId) {
|
|
|
|
|
]);
|
|
|
|
|
return $designations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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' => ['!=' => ""],
|
|
|
|
|
'id' => ['IN' => array_keys($financialTypes)],
|
|
|
|
|
]);
|
|
|
|
|
$descFinancialType = [];
|
|
|
|
|
if (!empty($result['values'])) {
|
|
|
|
|
$descFinancialType = array_column($result['values'], 'description', 'id');
|
|
|
|
|
}
|
|
|
|
|
return $descFinancialType + $financialTypes + ['other_financial_type' => ts('Other')];
|
|
|
|
|
}
|
|
|
|
|