How to import / export content type in drupal 8?

user3178593 picture user3178593 · Jun 28, 2017 · Viewed 9.7k times · Source

How to import / export content type with their related contents from one website to another website in drupal 8?

Answer

Cameron picture Cameron · Jul 11, 2018

You'll find the drupal/console command config:export:content:type will help here.

Create a module and then run this command and it will do all the hard work for you:

drupal config:export:content:type --module=new_module --remove-uuid --remove-config-hash content_type_to_export

This will put it in the config/install directory for the module. When you enable the module on your new site, it will run this automatically.

One gotcha I had was that it adds a couple of files for config already included in core. I just deleted them and it was all fine. Basically if a yml file doesn't reference your content type in its file name, then you might not need it.

For more information:

drupal help config:export:content:type