Skip to content

Commit

Permalink
COMCL-333: Fix bug with empty target contact for file upload activities
Browse files Browse the repository at this point in the history
  • Loading branch information
shahrukh-compuco committed Nov 8, 2023
1 parent bb47e85 commit bef0b7a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* Remove empty target contact from activity.
*
* CiviCRM errors out if an empty string is sent for target
* contact id and to solve this we remove the target_contact_id param
* for activity form if its value is empty string.
*/
class CRM_Civicase_Hook_ValidateForm_RemoveEmptyTargetContactFromActivity {

/**
* @param string $formName
* @param array $fields
* @param array $files
* @param CRM_Core_Form $form
* @param array $errors
*
* @return bool
*/
public function run(
string $formName,
array &$fields,
array &$files,
CRM_Core_Form $form,
array &$errors
): bool {
if (!$this->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;
}

/**
* @param string $formName
*
* @return bool
*/
private function shouldRun(string $formName): bool {
return $formName === 'CRM_Case_Form_Activity';
}

}
1 change: 1 addition & 0 deletions civicase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bef0b7a

Please sign in to comment.