2

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?

2 Answers 2

2

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

3
  • 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.
    – Coleman
    Commented Aug 30, 2015 at 17:13
  • 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
    – samuelsov
    Commented Jan 23, 2017 at 19:17
  • I mean, name => table_name... so it must be done via the database (name is not editable using civicrm/admin/options)
    – samuelsov
    Commented Jan 23, 2017 at 19:45
1

Since this is in the context of CiviCRM Extension, please consult the example to Create Custom Set via civix. 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

4
  • 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.
    – Mantas
    Commented Jul 29, 2015 at 9:38
  • 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
    – Mantas
    Commented Jul 29, 2015 at 9:49
  • As in the cited example github.com/civicrm/civihr/blob/master/hrqual/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.
    – Monish Deb
    Commented Jul 29, 2015 at 10:02
  • 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
    – Mantas
    Commented Jul 29, 2015 at 11:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.