From 5da5094bebf69621c7ce51dac186b5fb07f2b87b Mon Sep 17 00:00:00 2001 From: shahrukh-compuco Date: Thu, 9 Nov 2023 00:03:41 +0500 Subject: [PATCH] COMCL-333: Fix bug with empty target contact for file upload activities --- .../RemoveEmptyTargetContactFromActivity.php | 64 +++++++++++++++++++ civicase.php | 1 + 2 files changed, 65 insertions(+) create mode 100644 CRM/Civicase/Hook/ValidateForm/RemoveEmptyTargetContactFromActivity.php diff --git a/CRM/Civicase/Hook/ValidateForm/RemoveEmptyTargetContactFromActivity.php b/CRM/Civicase/Hook/ValidateForm/RemoveEmptyTargetContactFromActivity.php new file mode 100644 index 000000000..03d1a6cf4 --- /dev/null +++ b/CRM/Civicase/Hook/ValidateForm/RemoveEmptyTargetContactFromActivity.php @@ -0,0 +1,64 @@ +shouldRun($formName)) { + return FALSE; + } + + $submittedData = &$form->controller->container(); + if (is_array($submittedData) + && isset($submittedData['values']['Activity']['target_contact_id']) + && $submittedData['values']['Activity']['target_contact_id'] === '' + ) { + unset($submittedData['values']['Activity']['target_contact_id']); + } + + return TRUE; + } + + /** + * Determines if the hook will run. + * + * @param string $formName + * Form Name. + * + * @return bool + * Returns TRUE the Hook should run. + */ + private function shouldRun(string $formName): bool { + return $formName === 'CRM_Case_Form_Activity'; + } + +} diff --git a/civicase.php b/civicase.php index 196181472..aa381a5b8 100644 --- a/civicase.php +++ b/civicase.php @@ -310,6 +310,7 @@ function civicase_civicrm_validateForm($formName, &$fields, &$files, &$form, &$e new CRM_Civicase_Hook_ValidateForm_SaveActivityDraft(), new CRM_Civicase_Hook_ValidateForm_SaveCaseTypeCategory(), new CRM_Civicase_Hook_ValidateForm_SendBulkEmail(), + new CRM_Civicase_Hook_ValidateForm_RemoveEmptyTargetContactFromActivity(), ]; foreach ($hooks as $hook) {