It’s always a good practice to have a development environment and production environment for any kind of development. This post is for Drupal 8 development.
You have created some views, and want to port it to your production environment or want to share this with someone.
The Manual way
You can always create view manually, and change the configuration one by one manually. And, all done. But, still, there is a chance of manual error.
Doing it Drupal way
Drupal allows you to export and import a view.
To export a view in Drupal 8, follow steps:
- Goto /admin/config/development/configuration
You will See Synchronize title and 3 tabs:
Synchronize | Import | Export
- Click on Export. You will See two items:
Full Archive | Single Item
- Click on Single Item
You will be asked for Configuration Type from the drop-down.
- Second drop down:"Configuration name", will be populated with all the views.
- Select the desired view.
- As you select, the next text area: "Here is your configuration" will be populated with a yml
- You need to copy this yml
Now goto site, where you want to import that view. Follow steps:
- Goto: /admin/config/development/configuration/single/import
- Configuration type as View
- Paste the yml in the textarea showing next.
- Click on Import
If you see no error, your view has been successfully imported.
In your view, you might have referred some fields from some content type. You need to ensure that the field names are same in both environments. Else, you need to modify the yml copied.
For example, You might have created a new image style named: 300x200 in the development environment. And, you have not created this image style in a production environment.
Your yml have this reference, and when you import. It will throw an error saying that this image style is not found. You will need to create that image style, and then try again Or renaming that image style in yml, and then import.