howto

Ease the creation of fields and instances programatically

So you want to build a module that provides some fields and instances for an entity type. Let's start with a quick summary to get in context.

As you should know, fields in drupal are thingies that exist on its own, though they're useless if not attached to entities. Fields are tied to entities through instances. So to attach a field to a node or any other type of entity, it's needed to create instances. In this way, an instance is identified by the field name it instantiates and the entity type - bundle tuple it is tied to.

In Drupal's admin UI, creating fields and instances is overlapped: when you create a field, you're also creating an instance. On the other hand, when you're reusing an existing field, you're just creating a new instance of it.

Last but not least, part of the configuration you can see in the UI pertains to the field definition, and part to the field instance. So field configuration is the same for all of its instances, and instance configuration is specific and not shared by other instances.

Subscribe to RSS - howto