Answers.Body: <p>to CRM_Core_BAO_CustomGroup::mapTableName
  I had to add this:</p>
  
  <pre><code>case 'Lead':
      return 'civicrm_lead';
  </code></pre>
  
  <p>after that I'm able to add custom fields for my custom entity. </p>
  
  <p>so steps to add custom data for custom entity you need these things:
  Add entity to this group cg_extend_objects
  and then map type to table here: CRM_Core_BAO_CustomGroup::mapTableName</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-23T19:17:17.530Z
Answers.Text: In 4.7, instead of patching core, it seems to be possible to add a value in the option group 'cg_extend_objects' with the value => table_name
Answers.UserDisplayName: samuelsov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-23T19:45:45.260Z
Answers.Text: I mean, name => table_name... so it must be done via the database (name is not editable using civicrm/admin/options)
Answers.UserDisplayName: samuelsov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-30T17:13:05.220Z
Answers.Text: It would good to patch that function to auto-discover new entities so it doesn't require that kind of hack in core to use your extension.
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-30T09:34:37.797Z
Answers.LastActivityDate: 2015-08-30T09:34:37.797Z
Answers.UserDisplayName: Mantas
Answers.Body: <p>Since this is in the context of CiviCRM Extension, please consult the example to <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Create+a+Module+Extension#CreateaModuleExtension-Addcustomfields%28CiviCRMv4.4+%29" rel="nofollow">Create Custom Set via civix</a>. Or for quick reference check the xml file used to create custom set for one of the CiviHR module <a href="https://github.com/civicrm/civihr/blob/master/hrqual/xml/auto_install.xml" rel="nofollow">https://github.com/civicrm/civihr/blob/master/hrqual/xml/auto_install.xml</a>  </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-29T09:38:57.273Z
Answers.Text: I dont want custom fields to be installed while enabling module. I want user on his own to be able to create custom field set for custom entity.
Answers.UserDisplayName: Mantas
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-29T09:49:57.597Z
Answers.Text: by custom entity I mean: I have table with some data and user should be able to create custom fields which would be attached to records in that table. I hope its more clear
Answers.UserDisplayName: Mantas
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-29T10:02:38.863Z
Answers.Text: As in the cited example https://github.com/civicrm/civihr/blob/master/hrqual/xml/auto_install.xml , its not necessary to mention the <customField> tag to create custom field, just exclude the <customField> part with only <customGroup> tag information and custom-set table with no custom field(s) will be created. Apologies for not be clear, as I shared the xml for your reference.
Answers.UserDisplayName: Monish Deb
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-29T11:16:23.967Z
Answers.Text: there are 2 issues with this:
  1: I need to extend Entity. It doesnt work the way I did it, why it should work this way? Because problem is when CiviCrm tries to create table and puts foreign key it references "Leads" instead of its table. So somehow it doesnt take "Leads" configuration  2 I develop it as Civi component not as Civi Module so there is no auto_install
Answers.UserDisplayName: Mantas
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-28T17:12:30.443Z
Answers.LastActivityDate: 2015-07-29T10:03:00.177Z
Answers.LastEditDate: 2015-07-29T10:03:00.177Z
Answers.UserDisplayName: Monish Deb
Body: <p>I want to create custom field set for my custom entity. </p>
  
  <p>I have Lead.xml</p>
  
  <p>and there:
  <code>
    &lt; class >Lead&lt; /class >
    &lt; name >civicrm_lead&lt; /name >
  </code></p>
  
  <p>inside cg_extend_objects I put title:Lead, value:Lead</p>
  
  <p>But I'm not able to create custom field set for Lead now.</p>
  
  <p>I've tried to debug it.
  to CRM_Core_BAO_SchemaHandler::createTable
  this array is passed:
  <code>
  Array
  (
      [name] => civicrm_value_cccc1_16
      [is_multiple] => 0
      [attributes] => ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci
      [fields] => Array
          (
              [0] => Array
                  (
                      [name] => id
                      [type] => int unsigned
                      [primary] => 1
                      [required] => 1
                      [attributes] => AUTO_INCREMENT
                      [comment] => Default MySQL primary key
                  )</p>
  
  <pre><code>        [1] =&gt; Array
              (
                  [name] =&gt; entity_id
                  [type] =&gt; int unsigned
                  [required] =&gt; 1
                  [comment] =&gt; Table that this extends
                  [fk_table_name] =&gt; Lead
                  [fk_field_name] =&gt; id
                  [fk_attributes] =&gt; ON DELETE CASCADE
              )
  
      )
  
  [indexes] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [unique] =&gt; 1
                  [field_name_1] =&gt; entity_id
              )
  
      )
  </code></pre>
  
  <p>)
  </code></p>
  
  <p>and this SQL is generated:
  CREATE TABLE civicrm_value_cccc4_18 ( <code>id</code> int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key', <code>entity_id</code> int unsigned NOT NULL COMMENT 'Table that this extends', PRIMARY KEY ( id ), UNIQUE INDEX unique_entity_id ( entity_id ), CONSTRAINT FK_civicrm_value_cccc4_18_entity_id FOREIGN KEY ( <code>entity_id</code> ) REFERENCES Lead ( id ) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;</p>
  
  <p>It doesn't take table for Lead entity. Is there any extra coding needed for this?</p>
  
Tags: <custom-fields>
Title: Custom field set for custom entity
ThreadText: # Custom field set for custom entity
  
  (Asked by: username_0 on 2015-07-28)
  
  I want to create custom field set for my custom entity. 
  I have Lead.xml
  and there:
  
    < class >Lead< /class >
    < name >civicrm_lead< /name >
  
  inside cg_extend_objects I put title:Lead, value:Lead
  But I'm not able to create custom field set for Lead now.
  I've tried to debug it.
  to CRM_Core_BAO_SchemaHandler::createTable
  this array is passed:
  
  Array
  (
      [name] => civicrm_value_cccc1_16
      [is_multiple] => 0
      [attributes] => ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci
      [fields] => Array
          (
              [0] => Array
                  (
                      [name] => id
                      [type] => int unsigned
                      [primary] => 1
                      [required] => 1
                      [attributes] => AUTO_INCREMENT
                      [comment] => Default MySQL primary key
                  )
          [1] => Array
              (
                  [name] => entity_id
                  [type] => int unsigned
                  [required] => 1
                  [comment] => Table that this extends
                  [fk_table_name] => Lead
                  [fk_field_name] => id
                  [fk_attributes] => ON DELETE CASCADE
              )
  
      )
  
  [indexes] => Array
      (
          [0] => Array
              (
                  [unique] => 1
                  [field_name_1] => entity_id
              )
  
      )
  
  )
  
  and this SQL is generated:
  CREATE TABLE civicrm_value_cccc4_18 ( id int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key', entity_id int unsigned NOT NULL COMMENT 'Table that this extends', PRIMARY KEY ( id ), UNIQUE INDEX unique_entity_id ( entity_id ), CONSTRAINT FK_civicrm_value_cccc4_18_entity_id FOREIGN KEY ( entity_id ) REFERENCES Lead ( id ) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
  It doesn't take table for Lead entity. Is there any extra coding needed for this?
  
  **Tags:** custom-fields
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2015-08-30. Score: 2 | Accepted answer
  
  to CRM_Core_BAO_CustomGroup::mapTableName
  I had to add this:
  case 'Lead':
      return 'civicrm_lead';
  
  after that I'm able to add custom fields for my custom entity. 
  so steps to add custom data for custom entity you need these things:
  Add entity to this group cg_extend_objects
  and then map type to table here: CRM_Core_BAO_CustomGroup::mapTableName
  
  > **Comments:**
  > **username_2**: It would good to patch that function to auto-discover new entities so it doesn't require that kind of hack in core to use your extension.  
  > **username_1**: In 4.7, instead of patching core, it seems to be possible to add a value in the option group 'cg_extend_objects' with the value => table_name  
  > **username_1**: I mean, name => table_name... so it must be done via the database (name is not editable using civicrm/admin/options)  
  
  ---
  
  ### Answer by username_3 on 2015-07-28. Score: 1
  
  Since this is in the context of CiviCRM Extension, please consult the example to [Create Custom Set via civix](http://wiki.civicrm.org/confluence/display/CRMDOC/Create+a+Module+Extension#CreateaModuleExtension-Addcustomfields%28CiviCRMv4.4+%29). Or for quick reference check the xml file used to create custom set for one of the CiviHR module <https://github.com/civicrm/civihr/blob/master/hrqual/xml/auto_install.xml>
  
  > **Comments:**
  > **username_0**: I dont want custom fields to be installed while enabling module. I want user on his own to be able to create custom field set for custom entity.  
  > **username_0**: by custom entity I mean: I have table with some data and user should be able to create custom fields which would be attached to records in that table. I hope its more clear  
  > **username_3**: As in the cited example https://github.com/civicrm/civihr/blob/master/hrqual/xml/auto_install.xml , its not necessary to mention the <customField> tag to create custom field, just exclude the <customField> part with only <customGroup> tag information and custom-set table with no custom field(s) will be created. Apologies for not be clear, as I shared the xml for your reference.  
  > **username_0**: there are 2 issues with this: 1: I need to extend Entity. It doesnt work the way I did it, why it should work this way? Because problem is when CiviCrm tries to create table and puts foreign key it references "Leads" instead of its table. So somehow it doesnt take "Leads" configuration  2 I develop it as Civi component not as Civi Module so there is no auto_install  
  
  ---
  
  