Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMCL-333: Fix Bug With Empty Target Contact For File Upload Activities #993

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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 {

/**
* Implement the remove empty target contact functionality.
*
* @param string $formName
* Form Name.
* @param array $fields
* Fields List.
* @param array $files
* Files list.
* @param CRM_Core_Form $form
* Form Class object.
* @param array $errors
* Errors.
*
* @return bool
* TRUE if the hook ran, false otherwise.
*/
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;
}

/**
* 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';
}

}
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
Loading