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 5da5094
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
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,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'; | ||
} | ||
|
||
} |
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