Body: <p>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 (<a href="https://github.com/civicrm/civicrm-core/blob/e70cec100c435fe48e472f272f409d3887dcf8dc/CRM/Case/ManagedEntities.php#L84" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/e70cec100c435fe48e472f272f409d3887dcf8dc/CRM/Case/ManagedEntities.php#L84</a>) .. 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  <strong>hrcase_createDefaultCaseTypes();</strong> , and here is the function implementation :</p>
  
  <pre><code>function hrcase_createDefaultCaseTypes()  {
    hrcase_updateSystemActivityTypes('CiviTask');
    $caseTypes = include __DIR__ . '/CRM/HRCase/DefaultCaseTypes.php';
    foreach ($caseTypes as $case)  {
    $params = ['name' =&gt; $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' =&gt; 'Revoke access to databases'],
      ['name' =&gt; 'Block work email ID']
    ];
  hrcase_createDefaultActivityTypes($specialActivityTypes, 'CiviCase');}
  </code></pre>
  
  <p>here is the links for the rest of  functions and files to help understanding this  :</p>
  
  <p><a href="https://github.com/civicrm/civihr/blob/PCHR-459-2nd-test/hrcase/CRM/HRCase/DefaultCaseTypes.php" rel="nofollow noreferrer">https://github.com/civicrm/civihr/blob/PCHR-459-2nd-test/hrcase/CRM/HRCase/DefaultCaseTypes.php</a></p>
  
  <p><a href="https://github.com/civicrm/civihr/blob/PCHR-459-2nd-test/hrcase/hrcase.php#L565" rel="nofollow noreferrer">https://github.com/civicrm/civihr/blob/PCHR-459-2nd-test/hrcase/hrcase.php#L565</a></p>
  
  <p><a href="https://github.com/civicrm/civihr/blob/PCHR-459-2nd-test/hrcase/hrcase.php#L780" rel="nofollow noreferrer">https://github.com/civicrm/civihr/blob/PCHR-459-2nd-test/hrcase/hrcase.php#L780</a></p>
  
  <p>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</p>
  
  <p>Here is a screenshots :</p>
  
  <p><a href="https://i.sstatic.net/LjdkA.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LjdkA.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.sstatic.net/ZQiJy.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ZQiJy.png" alt="enter image description here"></a></p>
  
  <p>So why CiviCRM still create these acitivty types since I don't use managed entities here , how can I avoid that ?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-09T19:40:52.497Z
Comments.Text: Since your new component is so similar to CiviCase, have you considered just instead customizing CiviCase?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-09T22:43:54.877Z
Comments.Text: 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.
Comments.UserDisplayName: Matt
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-09T23:28:36.013Z
Comments.Text: Maybe try a debugger to see when they getting created? I don't see anything obvious in those codes.
Comments.UserDisplayName: Demerit
Tags: <civicase><developer><hooks>
Title: creating case types with different component than CiviCase for attached activity types
ThreadText: # creating case types with different component than CiviCase for attached activity types
  
  (Asked by: username_0 on 2016-08-09)
  
  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](https://i.sstatic.net/LjdkA.png)](https://i.sstatic.net/LjdkA.png)
  
  [![enter image description here](https://i.sstatic.net/ZQiJy.png)](https://i.sstatic.net/ZQiJy.png)
  
  So why CiviCRM still create these acitivty types since I don't use managed entities here , how can I avoid that ?
  
  **Tags:** civicase, developer, hooks
  
  > **Comments:**
  > **username_1**: Since your new component is so similar to CiviCase, have you considered just instead customizing CiviCase?  
  > **username_0**: 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.  
  > **username_1**: Maybe try a debugger to see when they getting created? I don't see anything obvious in those codes.  
  
  ---
  
  ## 0 answers
  
  