0

I've followed How to create views programmatically in Drupal 8, but as I asked in this topic, my view doesn't appear in my list.

When I install my module twice (Enable -> Uninstall -> Enable), I have an error:

Configuration object views.views.viewsname already exist

I also tried to import it directly in Drupal, copied the exact same code and this worked.

  • Did clear cache? – Jimmy Ko Oct 24 '16 at 13:12
  • yeah did drush cr, clear cash & co but nothing changed – Antoine Oct 24 '16 at 13:20
  • Maybe this is stupid question. Did you enable the module? – Jimmy Ko Oct 24 '16 at 13:22
  • man :p of course, I'll add some detail in the post – Antoine Oct 24 '16 at 13:23
1

As the error says, the problem isn't with your module, but simply that the configuration your module is trying to create already exists in your installation.

You have two options to get it installed:

  1. delete the configuration first, in the UI or programatically (How do I remove a configuration object from the active configuration?) and then add an enforced dependendency on your module, to make sure it is removed when your module is uninstalled. Note that you must first remove the config, the enforced dependency that removes your config only works once installed using the new definition.
  2. Provide as optional config in config/optional instead of config/install. Optional config is different from other config in two ways:
    • First, it is only installed when all the required dependencies exist. That is useful if you have optional integration with another module and if it is installed, provide some configuration for it. This even works if that other module is installed later on. Configuration with missing dependencies in config/install fails with an error as Drupal assumes your module will not work correctly if the config can not be installed.
    • Second, it will also be silently skipped if the config exists already, which is the relevant thing for your case. It will however also be silently skipped if the existing config just happens to be a view with the same name that is actually something else.
  • The error only occurs the second time, that means he installs something the first time but I can't see the view, currently solving the configuration error is not really the purpose of my question, it's just here to say "yeah the module is doing something since I can't install it twice in a row, but it's still not doing what it's supposed to do" – Antoine Oct 25 '16 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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