Skip to content

Commit

Permalink
Generate button links in PHP instead of smarty for ContributionView form
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Feb 3, 2022
1 parent 1ff21bd commit 8a96610
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 57 deletions.
74 changes: 73 additions & 1 deletion CRM/Contribute/Form/ContributionView.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function preProcess() {
}
$this->assign('is_template', $values['is_template']);

$noACL = FALSE;
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::VIEW) {
$financialTypeID = CRM_Contribute_PseudoConstant::financialType($values['financial_type_id']);
CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'view');
Expand All @@ -60,7 +61,7 @@ public function preProcess() {
}
}
elseif ($this->_action & CRM_Core_Action::VIEW) {
$this->assign('noACL', TRUE);
$noACL = TRUE;
}
CRM_Contribute_BAO_Contribution::resolveDefaults($values);

Expand Down Expand Up @@ -221,6 +222,77 @@ public function preProcess() {
$this->assign('component', 'contribution');
}
$this->assignPaymentInfoBlock($id);

$searchKey = NULL;
if ($this->controller->_key) {
$searchKey = $this->controller->_key;
}
if ((
CRM_Core_Permission::check('edit_contributions')
&& CRM_Core_Permission::check('edit contributions of type ' . $financialTypeID)
&& !empty($canEdit)
) || (CRM_Core_Permission::check('edit contributions') && $noACL)) {
$urlParams = "reset=1&id={$id}&cid={$values['contact_id']}&action=update&context={$context}";
if (($context === 'fulltext' || $context === 'search') && $searchKey) {
$urlParams = "reset=1&id={$id}&cid={$values['contact_id']}&action=update&context={$context}&key={$searchKey}";
}
$linkButtons[] = [
'title' => ts('Edit'),
'url' => 'civicrm/contact/view/contribution',
'qs' => $urlParams,
'icon' => 'fa-pencil',
'accesskey' => 'e',
];
if (!empty($paymentButtonName)) {
$linkButtons[] = [
'title' => $paymentButtonName,
'url' => 'civicrm/payment',
'qs' => "action=add&reset=1&component=contribution&id={$id}&cid={$values['contact_id']}",
'icon' => 'fa-plus-circle',
];
}
}

if ((
CRM_Core_Permission::check('delete in CiviContribute')
&& CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($financialTypeID))
&& !empty($canDelete)
) || (CRM_Core_Permission::check('delete in CiviContribute') && $noACL)) {
$urlParams = "reset=1&id={$id}&cid={$values['contact_id']}&action=delete&context={$context}";
if (($context === 'fulltext' || $context === 'search') && $searchKey) {
$urlParams = "reset=1&id={$id}&cid={$values['contact_id']}&action=delete&context={$context}&key={$searchKey}";
}
$linkButtons[] = [
'title' => ts('Delete'),
'url' => 'civicrm/contact/view/contribution',
'qs' => $urlParams,
'icon' => 'fa-trash',
];
}

$pdfUrlParams = "reset=1&id={$id}&cid={$values['contact_id']}";
$emailUrlParams = "reset=1&id={$id}&cid={$values['contact_id']}&select=email";
if ($invoicing && empty($is_template)) {
if (($values['contribution_status'] != 'Refunded') && ($values['contribution_status'] != 'Cancelled')) {
$invoiceButtonText = ts('Download Invoice');
}
else {
$invoiceButtonText = ts('Download Invoice and Credit Note');
}
$linkButtons[] = [
'title' => $invoiceButtonText,
'url' => 'civicrm/contribute/invoice',
'qs' => $pdfUrlParams,
'icon' => 'fa-download',
];
$linkButtons[] = [
'title' => ts('Email Invoice'),
'url' => 'civicrm/contribute/invoice/email',
'qs' => $emailUrlParams,
'icon' => 'fa-paper-plane',
];
}
$this->assign('linkButtons', $linkButtons ?? []);
}

/**
Expand Down
56 changes: 0 additions & 56 deletions templates/CRM/Contribute/Form/ContributionView.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,6 @@
<div class="crm-block crm-content-block crm-contribution-view-form-block">
<div class="action-link">
<div class="crm-submit-buttons">
{if (call_user_func(array('CRM_Core_Permission','check'), 'edit contributions') && call_user_func(array('CRM_Core_Permission', 'check'), "edit contributions of type $financial_type") && !empty($canEdit)) ||
(call_user_func(array('CRM_Core_Permission','check'), 'edit contributions') && $noACL)}
{assign var='urlParams' value="reset=1&id=$id&cid=$contact_id&action=update&context=$context"}
{if ( $context eq 'fulltext' || $context eq 'search' ) && $searchKey}
{assign var='urlParams' value="reset=1&id=$id&cid=$contact_id&action=update&context=$context&key=$searchKey"}
{/if}
<a class="button" href="{crmURL p='civicrm/contact/view/contribution' q=$urlParams}" accesskey="e"><span>
<i class="crm-i fa-pencil" aria-hidden="true"></i> {ts}Edit{/ts}</span>
</a>
{if !empty($paymentButtonName)}
<a class="button" href='{crmURL p="civicrm/payment" q="action=add&reset=1&component=`$component`&id=`$id`&cid=`$contact_id`"}'><i class="crm-i fa-plus-circle" aria-hidden="true"></i> {ts}{$paymentButtonName}{/ts}</a>
{/if}
{/if}
{if (call_user_func(array('CRM_Core_Permission','check'), 'delete in CiviContribute') && call_user_func(array('CRM_Core_Permission', 'check'), "delete contributions of type $financial_type") && !empty($canDelete)) || (call_user_func(array('CRM_Core_Permission','check'), 'delete in CiviContribute') && $noACL)}
{assign var='urlParams' value="reset=1&id=$id&cid=$contact_id&action=delete&context=$context"}
{if ( $context eq 'fulltext' || $context eq 'search' ) && $searchKey}
{assign var='urlParams' value="reset=1&id=$id&cid=$contact_id&action=delete&context=$context&key=$searchKey"}
{/if}
<a class="button" href="{crmURL p='civicrm/contact/view/contribution' q=$urlParams}"><span>
<i class="crm-i fa-trash" aria-hidden="true"></i> {ts}Delete{/ts}</span>
</a>
{/if}
{assign var='pdfUrlParams' value="reset=1&id=$id&cid=$contact_id"}
{assign var='emailUrlParams' value="reset=1&id=$id&cid=$contact_id&select=email"}
{if $invoicing && empty($is_template)}
<div class="css_right">
<a class="button no-popup" href="{crmURL p='civicrm/contribute/invoice' q=$pdfUrlParams}">
<i class="crm-i fa-download" aria-hidden="true"></i>
{if $contribution_status != 'Refunded' && $contribution_status != 'Cancelled' }
{ts}Download Invoice{/ts}</a>
{else}
{ts}Download Invoice and Credit Note{/ts}</a>
{/if}
<a class="button" href="{crmURL p='civicrm/contribute/invoice/email' q=$emailUrlParams}">
<i class="crm-i fa-paper-plane" aria-hidden="true"></i>
{ts}Email Invoice{/ts}</a>
</div>
{/if}
{include file="CRM/common/formButtons.tpl" location="top"}
</div>
</div>
Expand Down Expand Up @@ -328,24 +290,6 @@
{/if}

<div class="crm-submit-buttons">
{if (call_user_func(array('CRM_Core_Permission','check'), 'edit contributions') && call_user_func(array('CRM_Core_Permission', 'check'), "edit contributions of type $financial_type") && $canEdit) ||
(call_user_func(array('CRM_Core_Permission','check'), 'edit contributions') && $noACL)}
{assign var='urlParams' value="reset=1&id=$id&cid=$contact_id&action=update&context=$context"}
{if ( $context eq 'fulltext' || $context eq 'search' ) && $searchKey}
{assign var='urlParams' value="reset=1&id=$id&cid=$contact_id&action=update&context=$context&key=$searchKey"}
{/if}
<a class="button" href="{crmURL p='civicrm/contact/view/contribution' q=$urlParams}" accesskey="e"><span><i class="crm-i fa-pencil" aria-hidden="true"></i> {ts}Edit{/ts}</span></a>
{if $paymentButtonName}
<a class="button" href='{crmURL p="civicrm/payment" q="action=add&reset=1&component=`$component`&id=`$id`&cid=`$contact_id`"}'><i class="crm-i fa-plus-circle" aria-hidden="true"></i> {ts}{$paymentButtonName}{/ts}</a>
{/if}
{/if}
{if (call_user_func(array('CRM_Core_Permission','check'), 'delete in CiviContribute') && call_user_func(array('CRM_Core_Permission', 'check'), "delete contributions of type $financial_type") && $canDelete) || (call_user_func(array('CRM_Core_Permission','check'), 'delete in CiviContribute') && $noACL)}
{assign var='urlParams' value="reset=1&id=$id&cid=$contact_id&action=delete&context=$context"}
{if ( $context eq 'fulltext' || $context eq 'search' ) && $searchKey}
{assign var='urlParams' value="reset=1&id=$id&cid=$contact_id&action=delete&context=$context&key=$searchKey"}
{/if}
<a class="button" href="{crmURL p='civicrm/contact/view/contribution' q=$urlParams}"><span><i class="crm-i fa-trash" aria-hidden="true"></i> {ts}Delete{/ts}</span></a>
{/if}
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
</div>
Expand Down

0 comments on commit 8a96610

Please sign in to comment.