added code to show custom fields on View Contribution screen

This commit is contained in:
CiviWare Solutions 2018-12-21 16:26:41 +00:00
parent d6746941be
commit f9fe27054a
2 changed files with 112 additions and 0 deletions

View File

@ -148,3 +148,29 @@ function softcreditcustomfields_civicrm_alterSettingsFolders(&$metaDataFolders =
function softcreditcustomfields_civicrm_entityTypes(&$entityTypes) {
_softcreditcustomfields_civix_civicrm_entityTypes($entityTypes);
}
/**
* Implements hook_civicrm_buildForm().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm
*/
function softcreditcustomfields_civicrm_buildForm($formName, &$form) {
if ('CRM_Contribute_Form_ContributionView' == $formName) {
$softCredits = $form->get_template_vars('softContributions');
if (!empty($softCredits)) {
$softCreditIds = [];
foreach ($softCredits as $key => $softCredit) {
$softCreditIds[] = $softCredit['soft_credit_id'];
// add custom data of type soft credit
$groupTree = CRM_Core_BAO_CustomGroup::getTree('ContributionSoft', NULL, $softCredit['soft_credit_id']);
// we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
$softCredits[$key]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($form, $groupTree, FALSE, NULL, "dnc_");
}
$form->assign('softContributions', $softCredits);
$form->assign('softCreditIds', json_encode($softCreditIds));
CRM_Core_Region::instance('page-footer')->add(array(
'template' => "CRM/Contribute/Page/View/SoftCredit-Custom.tpl",
));
}
}
}

View File

@ -0,0 +1,86 @@
<div id="soft_credit_custom_field_extension_section" class="crm-accordion-wrapper crm-soft-credit-panel">
<div class="crm-accordion-header">
{ts}Soft Credit{/ts}
</div>
<div class="crm-accordion-body">
{foreach from=$softContributions item="softCont"}
<table class="crm-info-panel crm-soft-credit-listing">
<tr>
<td>
<a href="{crmURL p="civicrm/contact/view" q="reset=1&cid=`$softCont.contact_id`"}"
title="{ts}View contact record{/ts}">{$softCont.contact_name}
</a>
</td>
<td>{$softCont.amount|crmMoney:$currency}
{if $softCont.soft_credit_type_label}
({$softCont.soft_credit_type_label})
{/if}
</td>
</tr>
</table>
<!-- add custom data -->
<div class='softCredit_custom_data_{$softCont.soft_credit_id}'>
{foreach from=$softCont.custom item=customGroup key=cgId} {* start of outer foreach *}
{foreach from=$customGroup item=customValue key=cvId}
<div id="softCredit_custom_{$cgId}"
class="crm-collapsible crm-softCredit-custom-{$cgId}-accordion
{if $customValue.collapse_display}collapsed{/if}">
<div class="crm-accordion-header">
{$customValue.title}
</div>
<div class="crm-accordion-body">
{foreach from=$customValue.fields item=element key=field_id}
<table class="crm-info-panel">
<tr>
{if $element.options_per_line != 0}
<td class="label">{$element.field_title}</td>
<td class="html-adjust">
{* sort by fails for option per line. Added a variable to iterate through the element array*}
{foreach from=$element.field_value item=val}
{$val}
<br/>
{/foreach}
</td>
{else}
<td class="label">{$element.field_title}</td>
{if $element.field_data_type == 'Money'}
{if $element.field_type == 'Text'}
<td class="html-adjust">{$element.field_value|crmMoney}</td>
{else}
<td class="html-adjust">{$element.field_value}</td>
{/if}
{else}
<td class="html-adjust">
{if $element.contact_ref_id}
<a href='{crmURL p="civicrm/contact/view" q="reset=1&cid=`$element.contact_ref_id`"}'>
{/if}
{if $element.field_data_type == 'Memo'}
{$element.field_value|nl2br}
{else}
{$element.field_value}
{/if}
{if $element.contact_ref_id}
</a>
{/if}
</td>
{/if}
{/if}
</tr>
</table>
{/foreach}
</div>
</div>
{/foreach}
{/foreach} {* end of outer custom group foreach *}
<div class="clear" style="background:white !important; padding-bottom: 5px;"></div>
</div>
{/foreach}
</div>
</div>
<script type="text/javascript">
{literal}
CRM.$(function($) {
$("div.crm-soft-credit-pane").replaceWith($('div#soft_credit_custom_field_extension_section'));
});
{/literal}
</script>