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?
4 Answers
Views are configuration entities in Drupal 8, and can be exported via the Configuration Management module.
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":
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.
- Select 'Export' menu tab.
- Select 'Single item' sub menu tab.
- From the first item drop down 'Configuration type' select 'View'.
- 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.
-
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
-
1Yes Drupal Console supports CLI handling of export and import for D8. drupalconsole.com Prior to that, drush has some options. Commented Jul 21, 2016 at 15:40
-
2Be warned! Improper syntax on the command line for views in drupalconsole can wipe your view. Back up first. 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. Commented Jul 21, 2016 at 15:44
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
-
1For the reference: hechoendrupal.gitbooks.io/drupal-console/content/en/commands/… Commented Jun 2, 2018 at 13:03
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