From f35ca929ae8d51f2ba0f3e672662995b369faef9 Mon Sep 17 00:00:00 2001 From: Jaap Jansma Date: Mon, 31 May 2021 11:36:10 +0200 Subject: [PATCH] dev/financial#6 exclude template contributions from the contact summary and add a button to view them to the recurring contributions tab --- CRM/Contribute/Form/Search.php | 5 +++++ CRM/Contribute/Page/Tab.php | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index 8b2594e073..eac8152172 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -258,6 +258,11 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { // @todo - stop changing formValues - respect submitted form values, change a working array. $this->_formValues['contribution_test'] = 0; } + // We don't show template records in summaries or dashboards + if (empty($this->_formValues['is_template']) && $this->_force && !empty($this->_context) && ($this->_context === 'dashboard' || $this->_context === 'contribution')) { + // @todo - stop changing formValues - respect submitted form values, change a working array. + $this->_formValues['is_template'] = 0; + } foreach ([ 'contribution_amount_low', diff --git a/CRM/Contribute/Page/Tab.php b/CRM/Contribute/Page/Tab.php index 2d75e2096c..cdb4c55fdb 100644 --- a/CRM/Contribute/Page/Tab.php +++ b/CRM/Contribute/Page/Tab.php @@ -49,6 +49,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { */ public static function recurLinks(int $recurID, $context = 'contribution') { $paymentProcessorObj = Civi\Payment\System::singleton()->getById(CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorID($recurID)); + $templateContribution = CRM_Contribute_BAO_ContributionRecur::getTemplateContribution($recurID); $links = [ CRM_Core_Action::VIEW => [ 'name' => ts('View'), @@ -57,6 +58,16 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}", ], ]; + if (!empty($templateContribution['id'])) { + // Use constant CRM_Core_Action::PREVIEW as there is no such thing as view template. + // And reusing view will mangle the actions. + $links[CRM_Core_Action::PREVIEW] = [ + 'name' => ts('View Template'), + 'title' => ts('View Template Contribution'), + 'url' => 'civicrm/contact/view/contribution', + 'qs' => "reset=1&id={$templateContribution['id']}&cid=%%cid%%&action=view&context={$context}", + ]; + } if ( (CRM_Core_Permission::check('edit contributions') || $context !== 'contribution') && ($paymentProcessorObj->supports('ChangeSubscriptionAmount') -- 2.25.1