I followed the examples given at: https://www.drupal.org/node/2629550 to create a new content type. No problems there, the content type exists after I install the module. However, when I uninstall, and re-install with the custom field yml files it says to have, I get errors saying that the field storage doesn't exists. So I dug into core/modules/node/config/installand copied the field.storage.body and modified it for the field I wanted (username). The field created, however, when I install the module now... It says:

Drupal\Core\Field\FieldException: Attempt to create a configurable field for a non-configurable field storage. in Drupal\field\Entity\FieldConfig->__construct() (line 94 of C:\xampp\htdocs\drupal-8.4.4\drupal-8.4.4\core\modules\field\src\Entity\FieldConfig.php).

Here is the yml for the custom content type:

langcode: en
status: true
name: "Faculty Bio"
type: faculty_bio
description: "Faculty Bio"
help: ''
display_submitted: true

and the code for the custom field:

langcode: en
status: true
    - field.storage.node.body
    - node.type.faculty_bio
    - text
    - node
id: node.faculty_bio.username
field_name: field.storage.node.username
field_storage: username
entity_type: node
bundle: faculty_bio
label: Username
description: 'The username'
required: true
translatable: true
default_value: {}
default_value_callback: ''
  display_summary: true
field_type: text
  • Any certain reason why you are trying to create the content type programmatically? Just use core's Field UI module (/admin/structure/types) for a point and click interface. If you need the YML source you can export the configuration and copy them from the config sync directory into your module
    – Hudri
    Commented Jul 10, 2018 at 14:05
  • @Hudri I need the content type to be created when a module is installed. I will also be creating custom nodes programmatically later on in the module (which I already know how to do)
    – RJ Reedy
    Commented Jul 10, 2018 at 14:07
  • 1
    Fastest way still is to create them on a dummy site with field UI, export live config, and copy corresponding files to your_module/config/install. Remember that one content type consists of several config files (at least node_type + fields + field_storage + view modes + form modes). Drupal Console has a special option drupal config:export --remove-uuid --remove-config-hash to create config files without the site-specific keys.
    – Hudri
    Commented Jul 10, 2018 at 14:12
  • 2nd option would be Features module, basically does the same as CLI tools above.
    – Hudri
    Commented Jul 10, 2018 at 14:17
  • @Hudri ok so I did what you suggested, and flushed out the content type with the UI and did an export to get the yml for the content type. It still doesn't give me the fields in the content type, which is what I need flushed out. I need to be able to have that content type set up with a simple install of the module.
    – RJ Reedy
    Commented Jul 10, 2018 at 19:12

1 Answer 1


I created the content type in a test environment, and populated all of the fields I wanted using the UI. Then I went to the site configuration and did an export on the entire site. I pulled all of the yml files I needed for the fields and node types, and it works beautifully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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