Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate button links in PHP instead of smarty for ContributionView form #22588

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section should wind up removable with the view bounce being done here and then all the other checks can be done with the checkAccess being used further down

image

$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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will simplify down to that api checkAccess

&& !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)) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just yay

(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