drupal|May 14, 2018|2 min read

Drupal 8: How to Export and Import View

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.

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 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…

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…

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

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Server Security Best Practices — Complete Hardening Guide for Production Systems

Server Security Best Practices — Complete Hardening Guide for Production Systems

Every breach post-mortem tells the same story: an unpatched service, a…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF have been in the OWASP Top 10 for over a decade. They’re among the…

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

The OWASP Top 10 is the industry standard for web application security risks. If…