From 5fe494085b49434bd6e6ac486693364d7ac8e0e8 Mon Sep 17 00:00:00 2001 From: Camilo Rodriguez Date: Wed, 30 Dec 2020 08:28:29 +0000 Subject: [PATCH] MAE-391: Fix Giftaid Processing on Contribution Pages --- .../SetContributionGiftAidEligibility.php | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) mode change 100644 => 100755 CRM/Civigiftaid/Hook/Post/SetContributionGiftAidEligibility.php diff --git a/CRM/Civigiftaid/Hook/Post/SetContributionGiftAidEligibility.php b/CRM/Civigiftaid/Hook/Post/SetContributionGiftAidEligibility.php old mode 100644 new mode 100755 index 9873811..4b42041 --- a/CRM/Civigiftaid/Hook/Post/SetContributionGiftAidEligibility.php +++ b/CRM/Civigiftaid/Hook/Post/SetContributionGiftAidEligibility.php @@ -42,7 +42,7 @@ public function run($op, $objectName, $objectId, &$objectRef) { */ private function setGiftAidEligibilityStatus($contributionId) { $currentPath = CRM_Utils_System::currentPath(); - if (!in_array($currentPath, $this->getRequiredPaths())) { + if (!$this->isAllowedPath($currentPath)) { return; } @@ -147,20 +147,26 @@ private function getEligibilityFieldId() { catch (Exception $e) {} } - /** - * Returns paths/Urls where that needs this functionality implemented. + * Checks if the given path requires giftaid processing. + * + * @param $path + * Path to be evaluated. * - * @return array - * Required paths. + * @return bool + * If the path is one of the ones that needs to be processed for giftaid + * info. */ - private function getRequiredPaths() { - return [ - 'civicrm/member/add', // Add membership page - 'civicrm/contact/view/membership', // Add membership from contact view page - 'civicrm/participant/add', // Register event participant page - 'civicrm/contact/view/participant' //Add participant from contact view page + private function isAllowedPath($path) { + $allowedPaths = [ + 'civicrm/member/add', // Add membership page + 'civicrm/contact/view/membership', // Add membership from contact view page + 'civicrm/participant/add', // Register event participant page + 'civicrm/contact/view/participant', // Add participant from contact view page + 'civicrm/contribute/transact', // Create contribution from contribution page ]; + + return in_array($path, $allowedPaths); } /**