Programmatically create complex content types in Drupal 7

Most Drupal modules define their own database tables, and CRUD operations with these tables.

The excellent Content Copy CCK module helped and I used this to dynamically create content types, but it was kind of painful and required numerous one-way export and import iterations.

Enter the Drupal 7 Field API.

In previous Drupal versions, most modules defined their own tables, handled writing and reading data from tables, managed data entry and controlled presentation. Although Content Construction Kit (CCK) existed, few modules integrated with CCK. Generally, CCK was simply too unwieldy for modules to use. In Drupal 7, field API is in core and is an API (Application Programming Interface).

With CCK, the primary way to create a field was to administer a node type, add/modify a field and set up all this via the browser. Although it was possible to create fields programatically, it was a bolt on and not an easy task to accomplish. In field API, the primary way to create a field is through calling an API (using code) and the field UI (user interface) is an optional module which still allows the management of fields via the browser.

With Drupal 7, most modules will use field API for the tasks outlined above. One example of this is Organic Groups which relies on field API instead of using custom tables. Drupal 7 coding is becoming more “precision surgery” as most of the work is done by the field API, you just need a few well placed alter statements to get the customization you need.

via Field API tutorial | drupal.org.

Programmatically create complex content types in Drupal 7
Tagged on:

Leave a Reply

Your email address will not be published. Required fields are marked *