1

In Drupal 8, I want a view to be created when a module is installed.

I have already used the Features module to export the view, so I have the yml file that creates the view. I can't find what to include in order for this view to be created on installation of my module.

How can I achieve this?

1

1 Answer 1

6

If you have the YAML file, you can put this in: /modules/your_module/config/install.

Then the View will be imported, when the module is installed (but there will be no updates, if you change the YAML file, it will only be imported once).

Btw. to export the YAML file you don't need Features, you can do this with core (admin/config/development/configuration/single/export).

So you can remove the line uuid: from the YAML file, this is only valid for re-importing the YAML to the same or a cloned site.

2
  • Is that possible to make the view updatable? Or is it impossible by design (as the user is supposed to alter it with the UI?)
    – Aporie
    Nov 2, 2018 at 8:40
  • 1
    @Aporie, yes, the YAML file doesn't update automatically to protect user changes. But you can do this in a hook_update_N(), where you can target specific handler settings or overwrite the entire View with a new YAML if you don't care about user changes, see drupal.stackexchange.com/questions/214488/…
    – 4uk4
    Nov 2, 2018 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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