2

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 :

enter image description here

enter image description here

So why CiviCRM still create these acitivty types since I don't use managed entities here , how can I avoid that ?

3
  • Since your new component is so similar to CiviCase, have you considered just instead customizing CiviCase?
    – Demerit
    Aug 9, 2016 at 19:40
  • I didn't really witnessed the creation of this extension/component from the beginning so probably there is some business decision behind that .. so I am trying to live with the current situation but maybe later we will consider that , but thanks for the note.
    – Matt
    Aug 9, 2016 at 22:43
  • Maybe try a debugger to see when they getting created? I don't see anything obvious in those codes.
    – Demerit
    Aug 9, 2016 at 23:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.