From eae751395cc1bccf10f71c985dd93eff64de4c4b Mon Sep 17 00:00:00 2001 From: olayiwola-compucorp Date: Fri, 6 Oct 2023 08:51:09 +0100 Subject: [PATCH] CIWEMB-525: Ensure hook will only run where expected --- .../Hook/BuildForm/AddEntityReferenceToCustomField.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CRM/Civicase/Hook/BuildForm/AddEntityReferenceToCustomField.php b/CRM/Civicase/Hook/BuildForm/AddEntityReferenceToCustomField.php index dac5e0698..9e6b6c53d 100644 --- a/CRM/Civicase/Hook/BuildForm/AddEntityReferenceToCustomField.php +++ b/CRM/Civicase/Hook/BuildForm/AddEntityReferenceToCustomField.php @@ -17,7 +17,7 @@ class CRM_Civicase_Hook_BuildForm_AddEntityReferenceToCustomField { * Form Name. */ public function run(CRM_Core_Form &$form, $formName) { - if (!$this->shouldRun($formName)) { + if (!$this->shouldRun($form, $formName)) { return; } @@ -69,14 +69,17 @@ private function populateDefaultFields(CRM_Core_Form &$form, array &$customField /** * Checks if the hook should run. * + * @param \CRM_Core_Form $form + * Form object. * @param string $formName * Form Name. * * @return bool * True if hook should run, otherwise false. */ - public function shouldRun($formName) { - return $formName === "CRM_Contribute_Form_Contribution"; + public function shouldRun($form, $formName) { + $addOrUpdate = ($form->getAction() & CRM_Core_Action::ADD) || ($form->getAction() & CRM_Core_Action::UPDATE); + return $formName === "CRM_Contribute_Form_Contribution" && $addOrUpdate; } }