How to create fields programmatically in Drupal
Hacker by night
Categories
Drupal
Keywords
drupal

Have you ever faced a project where there are tons of fields to create and you just don't feel like clicking through the Drupal admin UI to configure them one by one ? Your fields might also be shared between several bundles and so you have to recreate them, again and again, for each node types. Then comes the time to place your fields in each form displays and each view displays...

Depending on the complexity of your project and the size of your team, the task of creating/configuring/placing fields correctly in Drupal can be very looong and tedious.

One wishes there were an easy way to declare and import the fields in one go.

This is what the Create Field Programmatically module is here for!

It allows developers and site builders to declare fields in a convenient manner - either in a simple YAML or a JSON file.

Here is an example of how you would create 5 fields attached to 3 differents node types: 

Work in progress...