2

The ECK module allows users to create custom entities.

When using this modules UI it is possible to create an entity type, and then attach multiple bundles to the entity.

It is also possible to create new entity types via code. This page shows an example which is as follows:

$entity_type =  new EntityType();
$entity_type->name = "eck_employee";
$entity_type->label = "Employee";
// Following line is taken from the eck_example.install file
$entity_type->addProperty('name', 'Name', 'text');
$entity_type->save();

This doesn't however show how to create and attach bundles.

Is it possible to attach bundles to entities when creating them via code (using ECK)?

1 Answer 1

3

I just found a blog article here which gives an example on how to do exactly this:

After creating the entity type with the example code I gave in the question a bundle can be created as simply as this:

$entity_type_bundle = new Bundle();
$entity_type_bundle->name = 'eck_employee';
$entity_type_bundle->entity_type = 'eck_employee';
$entity_type_bundle->save();
1
  • 1
    Apparently cache needs to be cleaned after doing this. ECK does not clean the necessary cache itself upon creation of the bundle. At least in the version I'm currently working with.
    – aross
    Jun 19, 2014 at 15:09

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.

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