32

I know how to do it in Drupal 6/7, but I cannot find where to export/import views in Drupal 8. From which admin page is possible to do it, in Drupal 8?

1

4 Answers 4

23

Views are configuration entities in Drupal 8, and can be exported via the Configuration Management module.

0
41

Views are available through configuration in Drupal 8, and can be exported via the Configuration Management interface.

In the admin menu select "Configuration" in the DEVELOPMENT section, select "Configuration synchronization": Drupal 8 Configuration Development menu area

In that menu area, the Export tab leads to the path: http://sitename/admin/config/development/configuration/single/export

In that area, a single view can be exported or imported, and the steps are about the same so I'll include Export here to help explain.

  1. Select 'Export' menu tab.
  2. Select 'Single item' sub menu tab.
  3. From the first item drop down 'Configuration type' select 'View'.
  4. From the second item drop down 'Configuration name' select the name of your view.

The result is a views.view.view_machine_name.yml "YAML" file that can be copy pasted into the 'Import' area.

4
  • Is there a way to do this without the UI? I want to be able to do this from a .module file. Commented Jul 20, 2016 at 14:21
  • 1
    Yes Drupal Console supports CLI handling of export and import for D8. drupalconsole.com Prior to that, drush has some options.
    – Adam John
    Commented Jul 21, 2016 at 15:40
  • 2
    Be warned! Improper syntax on the command line for views in drupalconsole can wipe your view. Back up first.
    – Adam John
    Commented Jul 21, 2016 at 15:42
  • From a .module you will need to look at the hooks used, there are some available for this... You should post a new question in order to follow StackExchange guidance.
    – Adam John
    Commented Jul 21, 2016 at 15:44
2

If you'd like to export a view for use in the default configuration of a custom module, you can run a Drupal Console command:

drupal config:export:view

See: config:export:view docs page.

1
0

Once a single view exported using the configuration management module, the view can be imported on a site of interested by creating a simple custom module and placing the yml file corresponding to the view in /config/install folder (remove the first line containing the uuid ) The view will be imported when activating the module

Not the answer you're looking for? Browse other questions tagged or ask your own question.