Skip to content

Commit

Permalink
CIWEMB-525: Ensure hook will only run where expected
Browse files Browse the repository at this point in the history
  • Loading branch information
olayiwola-compucorp committed Oct 6, 2023
1 parent 460c3e8 commit eae7513
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

}

0 comments on commit eae7513

Please sign in to comment.