How to import / export content type in drupal 8?
Solution 1
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
Solution 2
You can export/Import the content type and its field type & field storage via Synchronize feature provide by Drupal 8. Here this URL : admin/config/development/configuration
Solution 3
In this answer, I'll assume you have Drush installed. (If you don't, you can manage your config files here /admin/config/development/configuration).
Ok so, for your SiteA, open your terminal and goto the SiteA folder. Let's say you want your configs to be written in /sites/default/dev folder. So write the following command :
drush cex dev
It will export all of your website configurations. If you created new content types, they will be exported in the dev folder.
Now go to the dev folder of SiteA and copy every yml files related to your content type.
After, just paste them in the same folder but this time, in SiteB. Finally, in your terminal, goto SiteB folder and write the following command :
drush cim dev
Edit:
If you want to use dev folder, you'll need this config in your settings.php
$config_directories['dev'] = 'sites/default/dev';
Also, my answer only export content type configuration. Not it's content.
Solution 4
If the source and destination websites are the same and you can import/export configuration, using configuration export/import is the best solution, if not, using features module should be good solution for you .
The features module enables the capture and management of features in Drupal. A feature is a collection of Drupal entities which taken together satisfy a certain use-case.
Features provides a UI and API for taking different site building components from modules with exportables and bundling them together in a single feature module. A feature module is like any other Drupal module except that it contains additional information in its info file so that configuration can be checked, updated, or reverted programmatically.
Related videos on Youtube
user3178593
Updated on June 04, 2022Comments
-
user3178593 about 2 years
How to import / export content type with their related contents from one website to another website in drupal 8?
-
Hardoman almost 6 yearsImportant comment here is that if you want to migrate data between 6 and 7 versions, and create feature in D6, you won't be able to enable it as module in D7. Nevertheless if you go to /admin/build/features you still will be able to enable yur feature from there!
-
Andrew Magill over 3 yearsUnless I am missing something, this does NOT export actual content. Only the configuration.
-
Sohan Jangid over 3 yearsThe drush command worked as expected for Drupal 8.