6

I've got a module which contains a config/optional folder which has the content:

paragraphs.paragraphs_type.my_paragraph_id.yml
field.field.paragraph.my_paragraph_id.field_my_field.yml
field.storage.paragraph.field_my_field.yml
core.entity_form_display.paragraph.my_paragraph_id.yml
core.entity_view_display.paragraph.my_paragraph_id.yml

These files have been exported from an existing installation without uuid's. When I enable the module, the config does not import since the module paragraphs has not yet been enabled. When I enable paragraphs the paragraph type my_paragraph_id is created as expected. The field storage for field_my_field is also created, since I can create a new field based on the existing field field_my_field. Though, the field is not created on the paragraph itself.

I've tried moving the config files to config/install and then it simply works as expected; the field gets created on the paragraph just fine. But the module paragraph should be optional and only then the config should be created, therefor, I want it to be optional.

Why does the config/optional not install the field?

1 Answer 1

7

Optional config is only installed if it has an explicit dependency on a module that is being installed right now. Otherwise that configuration would be re-installed every time you install a module, even if it is something you chose to delete on a specific site.

The downside of that is that there are some grey areas of config that depends on config that depends on a module being installed that isn't found by this. Although that should also work but apparently does not in this case.

As a workaround, you can add an enforced dependency on the paragraphs module on those configurations that aren't being imported, then it should work. See https://www.drupal.org/node/2404447

1
  • I knew about enforced, but I figured that that only made sure that dependencies in that property were made persistent and not auto-calculated. I did not know that it would have impact on optional config and the import of that on install. Thanks! It works now!
    – Ambidex
    Commented Sep 28, 2017 at 7:41

Your Answer

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

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