π€ Skip the Field UI. β²οΈ Save time. π‘ Enjoy life!
This module allows you to create fields quickly from YAML or JSON files or from an array in your module.
It is particularly helpful in one of these situations:
π‘ Starting a Drupal project and planning content structure
π€ Creating the same fields across many content types
π¨ Decoupled architecture where front-end development takes place first
(allows potentially non-Drupal developers to work with real content and markup)
π₯± Tired of clicking around in the admin to create/place fields
How to use
With a custom module
In your own custom module, you can either (option 1) place custom configuration files in the install folder and/or (option 2) implement a hook to declare your fields.
- Option 1: in /mymodule/config/install/field_create.node.settings.yml
demo_field: name: demo_field label: This is my field type: string force: true bundles: page: label: This is a custom label for Pages article: label: This is a custom label for Articles
Now either a) enable your module to automatically import the config or b) import the configuration manually
drush cim --partial --source=modules/custom/mymodule/config/install
- Option 2: in /mymodule/mymodule.module file
/** * Implements hook_field_create_definitions(). */ function mymodule_field_create_definitions_alter(array &$definitions) { // Define your fields here by entity type. $definitions['node'] = [ 'demo_field' => [ 'name' => 'demo_field', 'label' => 'This is my field', 'type' => 'string', 'force' => FALSE, // No update once field exists. 'bundles' => [ 'page' => [], 'article' => [], ], ], ]; }
With the admin UI
Visit the admin settings page at Configuration > Development > Create Field Programmatically and paste your custom YAML configuration to declare your fields.
Note: an example file exists with detailed explanations about the custom YAML configuration. See the module's folder /example/field_create.node.settings.yml
Alternatively, you can enable the field_create_from_json submodule to convert JSON to YAML. An example file exists in the submodule's folder too at /example/node_fields.json
Create fields
With custom configurations in database AND with the module enabled in core.extensions.yml, you can now import your fields. Simply run this Drush command to create and/or to update your fields:
drush field_create
You can filter the field creation by entity type as follow:
drush field_create --entity-type-id node
Removing the module
You should remove this module once your fields are created as it is not meant to be deployed to realworld websites. This is only a developer tool :)
So uninstall the module if you don't need it anymore.
drush pmu field_create
Warning: all configurations for this module are deleted during the uninstall process (see details in the field_create_uninstall()).
---
This module is meant for development purpose only. You should not use it on production.
Related projects
- The latest version of Drush provides a method to create fields:
drush field-create
- Drupal Spec Tool maintained by Acquia provides a much more advanced tools to generate complete ERM from your project's specifications - including fields obviously
- Learn more about content modeling and existing helper modules listening to Talking Drupal #404 - Content Modeling
Project information
- Module categories: Developer Tools, Site Structure
- 11 sites report using this module
- Created by matthieuscarset on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.