forked from civicrm/org.civicrm.civicase
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COMCL-333: Fix bug with empty target contact for file upload activities
- Loading branch information
1 parent
bb47e85
commit bef0b7a
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
CRM/Civicase/Hook/ValidateForm/RemoveEmptyTargetContactFromActivity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters