1

Sorry for my bad english grammar. I write a module, allows the user to upload a file that contain list of content types infomation. Then my module will auto create content type for user. But i don't know how to create content type without hard define many .yml file.

0

If your content type is fairly straight forward (i.e. using only Drupal's fields), you can create the content type within the http://localhost/admin/structure/types/add link and once you have it built the way you want it you can export it via: http://localhost/admin/config/development/configuration/single/export.

It will even give you the name of yaml file to boot!

If that avenue is not sufficient then you can follow: This tutorial about building custom drupal content entities; it is lengthy in nature, which is why I will elide the details.

And if you're going to use that tutorial, then I would suggest using drupal console to generate the boilerplate code for you. It makes things quite simple. Drupal Console, among other things, manages the generation of content entity boilerplate code. It is quite helpful.

1
  • tks u! I know that way to create content type. But i has found programmatically to create by use $new_bundle = NodeType::create() and $new_bundle->save(). btw, tks for your anwser!. Aug 9 '17 at 8:27

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.