5

I'm trying to create a module that creates its own content types during installation. I understand that I need to use the Configuration API and the Entity API, but I'm having trouble adding Drupal-included fields to my custom type. From what I understand, I need to have a file for each field called field.field.node.content_type.field_type.yml. Am I correct in my understanding? If so, why are their two fields and where can I find the options to place in that configuration file? I have tried scouring through the API and I can't seem to find what I need.

This is the tutorial I'm following: https://www.drupal.org/docs/8/api/entity-api/creating-a-custom-content-type-in-drupal-8

1 Answer 1

5

Using the Configuration Manager module that comes with Drupal core to "automatically" as described in Managing your site's configuration is probably a better way to achieve what you want.

Create the new content types and their fields through the user interface.

On Configuration » Development » Configuration synchronization » Export » Single item, you just need to select your various pieces of content, one by one. For example, if you select Content type from the Configuration type menu and then a content type, you'll see the configuration you would need in the .yml file in the config/install directory for your module. Just eliminate that first uuid line. If you scroll down past the configuration text area, you'll see the name of the file name you need. For the Article content type, that would be node.type.article.yml.

You'll also need the field and field storage configuration types. Pay attention to the configuration dependencies and be sure you get all the pieces of configuration you need.

Once you get everything you need into configuration files, you can delete everything you created through the UI, reinstall your module, and verify everything works as expected. Otherwise, you can make changes through the user interface and export the configuration again. You could just edit the files directly, once you understand how everything is organized, especially if you're just making small changes.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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