user3178593
user3178593

Reputation: 113

How to import / export content type in drupal 8?

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

Upvotes: 9

Views: 15108

Answers (5)

Dino
Dino

Reputation: 21

Try the Content synchronization feature from the Mix module, which allows you to export/import and recreate block contents, menu item links and taxonomy terms between environments (sites)

You can easily choose which items to sync via UI like below: enter image description hereenter image description here

Upvotes: 0

JFC
JFC

Reputation: 586

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.

Upvotes: 3

Vernit Gupta
Vernit Gupta

Reputation: 339

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

Upvotes: 3

Cameron
Cameron

Reputation: 1015

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

Upvotes: 9

Yuseferi
Yuseferi

Reputation: 8700

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.

Upvotes: 1

Related Questions