We created an extension for tasks management which define a new civicrm component called CiviTask .. I want to create 4 case types (with attached activity Types set and a standard timeline ) when installing the extension but I want the attached activity types set have to be attached to CiviTask component instead of CiviCase component .. I tried to used hook_civicrm_caseTypes and then hook_civicrm_managed hook with no luck since civicrm is hardcoded to create the attached activity types for CiviCase component (https://github.com/civicrm/civicrm-core/blob/e70cec100c435fe48e472f272f409d3887dcf8dc/CRM/Case/ManagedEntities.php#L84) .. I tried to change the component ID field in extenstion postInstall function but hook_civicrm_caseTypes and hook_civicrm_managed hooks run after postInstall function so I cannot change anything there ... then I decided to drop hook_civicrm_caseTypes/hook_civicrm_managed hooks approach and doing stuff old school by creating these case types manually on extension life cycle ( install/disable/enable/uninstall ) so for extension install function I call this function hrcase_createDefaultCaseTypes(); , and here is the function implementation :
function hrcase_createDefaultCaseTypes() {
hrcase_updateSystemActivityTypes('CiviTask');
$caseTypes = include __DIR__ . '/CRM/HRCase/DefaultCaseTypes.php';
foreach ($caseTypes as $case) {
$params = ['name' => $case['name']];
$defaults = NULL;
$caseType = CRM_Case_BAO_CaseType::retrieve($params, $defaults);
if ($caseType == NULL) {
$caseParams = $case['params'];
CRM_Case_BAO_CaseType::create($caseParams);
hrcase_createDefaultActivityTypes($case['params']['definition'] ['activityTypes'], 'CiviTask');
}
}
$specialActivityTypes =
[
['name' => 'Revoke access to databases'],
['name' => 'Block work email ID']
];
hrcase_createDefaultActivityTypes($specialActivityTypes, 'CiviCase');}
here is the links for the rest of functions and files to help understanding this :
https://github.com/civicrm/civihr/blob/PCHR-459-2nd-test/hrcase/CRM/HRCase/DefaultCaseTypes.php
https://github.com/civicrm/civihr/blob/PCHR-459-2nd-test/hrcase/hrcase.php#L565
https://github.com/civicrm/civihr/blob/PCHR-459-2nd-test/hrcase/hrcase.php#L780
but even when creating case types and activities like this , civicrm will still create the activity types in the list so I end up with duplicate activity types one with component ID = CiviCase and a similar one with Component ID = CiviTask
Here is a screenshots :
So why CiviCRM still create these acitivty types since I don't use managed entities here , how can I avoid that ?