~/drupal/62-drupal-8-how-export-and-import-view.md

Drupal 8: How to Export and Import View

2 min readMay 14, 2018by Gorav Singal#import-drupal-view#export-drupal-view#backend
// TL;DR

Use Drupal 8 configuration synchronization to export views as YAML and import them into another environment, avoiding manual recreation.

Drupal 8: How to Export and Import View

Introduction

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.
    Select View
  • 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.

Common Error

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.

$ subscribe --weekly

One deep dive a week, in your inbox

System design, AI engineering, trading systems and interview prep. Tested code, real numbers. Free, and you can unsubscribe any time.

or read it on gyanbyte.substack.com

Share

Related Posts

Drupal Code: Fetch Link, Title, Category names, tag names from every article

Drupal Code: Fetch Link, Title, Category names, tag names from every article

See the code below: The output will be 4 columns separated by comma. You can…

Drupal: How to block a user by email programatically

Drupal: How to block a user by email programatically

Many times, while administering your drupal website, you must have encountered…

Drupal 7: How to save a node programmatically and add an image field from a public URL

Drupal 7: How to save a node programmatically and add an image field from a public URL

Note: I have public URLs of these images, which I want to save. return…

Drupal 7: How to implement cron tasks (hook_cron and hook_cron_queue_info) that takes much time

Drupal 7: How to implement cron tasks (hook_cron and hook_cron_queue_info) that takes much time

hook_cron() suggests to put tasks that executes in shorter time or non-resource…

Drupal Helpful codes for database queries

Drupal Helpful codes for database queries

Being a drupal user from last around 5 years, I used to know small codes for…

How to add alt attribute of images in all of my drupal articles or other content type

How to add alt attribute of images in all of my drupal articles or other content type

I have a custom content type, and there are around 2000 number of nodes in my…

Latest Posts

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

In the previous article I argued that AI is not killing software engineering…

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

A few months back I approved a PR that was almost entirely AI-generated. It…

How to Debug AI-Generated Code: Understand First, Fix Last

How to Debug AI-Generated Code: Understand First, Fix Last

In the last article I wrote about reviewing AI code before it goes in. This one…

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

Every few weeks somebody sends me a scary headline — “AI will replace all…

The Transactional Outbox Pattern: Never Lose an Event Again

The Transactional Outbox Pattern: Never Lose an Event Again

This is one of those patterns that looks like nothing until you get burnt once…

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Here is a question I like to ask in interviews: your bank account shows a…