In #2090115: Don't install a module when its default configuration has unmet dependencies we introduce the notion of optional configuration. When a module is installed all the config/optional directories are search for any configuration entities which have an entity type provided by the new module. This is the most basic dependency a module can have.

We can do better than this. We can determine if any optional configuration that does not exist has a dependency on the extension that is being installed and then create it if this condition is met. This means that modules can provide optional configuration the has multiple dependencies and it will be installed when all the dependencies are met.

For example, a module could provide a view which has a dependency on itself, Views and Block modules. The module itself does not have a dependency on Views or Block. It's installed before either of those modules. With HEAD if Block then Views is enabled the view will be created. If this occurred the other way around it would not be.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott’s picture

Status: Active » Needs review
Related issues: +#2460529: Migrations need to use the configuration entity dependency system
FileSize
9.82 KB
rteijeiro’s picture

Status: Needs review » Reviewed & tested by the community

Code seems fine. Not sure how to manually test it.

Berdir’s picture

+++ b/core/modules/config/src/Tests/ConfigInstallProfileOverrideTest.php
@@ -106,15 +106,10 @@ function testInstallProfileConfigOverwrite() {
+    // Installing db_log creates the optional configuration.
     $this->container->get('module_installer')->install(['dblog']);
     $this->rebuildContainer();
-    // Just installing db_log does not create the optional configuration.

db_log => dblog?

Tested this with monitoring, removed my custom code, only did some manual tests, but worked fine for them: #2461145: Remove custom optional config installation

alexpott’s picture

FileSize
1.01 KB
9.82 KB

Addressing #3

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Looks good to me, has ample test coverage and docs to explain what's happening. (It is an alexpott patch, after all! :D)

Committed and pushed to 8.0.x. Thanks!

  • webchick committed ccfaa23 on 8.0.x
    Issue #2460847 by alexpott: Allow optional configuration to be installed...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.