Problem/Motivation
Over in #3086824: SearchBlock plugins need to add in dependencies on the search page they submit to we discovered that if profile configuration in it's config/install directory depends on optional configuration provided by a module (or a theme) it'll fail with UnmetDependencies exception.
Proposed resolution
Install all optional configuration available before installing the install profile and then on subsequent module installs (such as the profile) install optional configuration alongside the the config/install configuration (as we do during regular module install outside of the Drupal installer).
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
The order optional configuration is installed during a site install has changed. If you maintain an install profile that creates content during your install profile's install hook. See Optional configuration from modules is installed before the install profile for more information.

| Comment | File | Size | Author |
|---|---|---|---|
| #51 | 3087130-51.patch | 7.47 KB | neslee canil pinto |
| #31 | 3087130-2-31.patch | 7.47 KB | alexpott |
| #31 | 30-31-interdiff.txt | 683 bytes | alexpott |
| #30 | interdiff-17-30.txt | 5.35 KB | aleevas |
| #30 | 3087130-30.patch | 7.43 KB | aleevas |
Comments
Comment #2
andypostInitial stub to test
Comment #3
alexpottSo here's the fix. What I don't understand at the moment is how the profile's optional configuration is being installed... we need to work that out before proceeding.
Comment #6
alexpottSo this is still broken but now we're in interesting circular dependencies issues. The umami block has a dependency on content but that content is only created after the block in installed. With this it happens the other way around. It works in HEAD because optional config is installed after the profile but what umami is doing is only possible of the current code in install_install_profile and installing all optional configuration after the install profile.
We could do
in install_install_profile() and that would be green. But the patch has a massive advantage in that this also fixes optional config install for modules installed after install_install_profile(). Distributions like Thunder have forms after profile installation that currently won't do a default config install. And in fact this happens in head with the option that enables the update module in the site configure form - the only reason we don't have a critical bug is that the Update module does not have any optional configuration.
Comment #8
andypostI recall there's config event to react on missing content for the config, but it looks like not quickfix, I used to explore it in #2849128: Add handling of ConfigEvent::IMPORT_MISSING_CONTENT
Also umami using migrations to import content so the content should go last
Comment #9
alexpottWhat's interesting is that I tried to do
i.e. re-save the block to fix the dependencies after installing demo_umami_content and it didn't work.
Comment #10
alexpottAh I just didn't read carefully enough - resaving the block does fix the dependencies - there's more than one block that we need to do this for. Here's a hopefully green patch!
This patch will fix a hard to find bugfix in Thunder which installs all optional configuration at the end of the install to fix this bug - see https://github.com/BurdaMagazinOrg/thunder-distribution/blob/8.x-2.x/thu...
Comment #11
andypostlooks like other's patch changes
Comment #12
alexpottRemoved extraneous code.
Comment #14
alexpottUnrelated random fail.
Comment #15
andypostOther then follow-up for dependencies it looks like RTBC... but needs other pair of eyes
I bet it needs todo and follow-up to debug why dependencies require resave
Comment #16
alexpottI don't think a follow-up is needed. This is plain chicken and egg. Config installation occurs during a module install before it's hook_install is done. So when
demo_umami_contentis installed during the profile's install hook. We create the optional block config but the content does not yet exist. Therefore the block dependencies cannot be correctly calculated. But content dependencies are "soft" so we allow them to be removed with no other changes to the block. Then afterdemo_umami_content's hook_install has fired the content exists so if we re-save them the dependencies are fixed. There's no simple way to fix this unless we can think of a way to create the content before the configuration.Comment #17
alexpottSo #16 opens an interesting fix for this. Modules can listen to their own preinstallation so we can import content then and then we have a better flow without having to re-save the blocks.
Comment #18
alexpottComment #19
rensingh99 commentedComment #20
alexpott@rensingh99 if you assign yourself an issue it'd be great if your comment says why. Going to unassign for now - if there are things you think the issue needs done it'd be great if you can add that to your comment.
Comment #21
rensingh99 commentedHi Alex,
The task status is `Needs Review`. I have some time which I can dedicate to review.
Hence I assigned it to myself. Please advise if i made a mistake.
Thanks
Ren
Comment #22
alexpottHi @rensingh99 normally people assign issues to themselves to state something like "I'm going to roll a new patch here so talk to me before doing the same thing" - it case of doing a review many people can do that at the same time so assigning yourself an issue is not necessary. The key thing is when assigning yourself an issue is to state what you're going to do otherwise assigning yourself an issue might stop someone else from doing a review or doing other needed work.
Comment #23
rensingh99 commentedHi,
I have created a custom profile and I have added all config install files for one content type except one dependent install file into profile_name/config/install.
That dependent config file I have added into module. And added that module in profile.info.yml in the list of install-module.
At the time of installing the module, I have gotten below error.
But after applying the patch. I have not got this error.
So, this patch is working great.
Thanks,
Ren
Comment #24
chr.fritschI also tested this patch with our Thunder distribution and I can confirm that it works. We can now get rid of some config install weirdness from the distribution.
If possible, I would also vote for a backport to 8.8.x
Comment #25
rensingh99 commentedI had posted this image in comment no#23. But somehow it was disappeared. So I was trying to place into comment #23.
Comment #26
chr.fritsch@rensingh99 Could you please explain your screenshot. Just posting some random screenshot without any explanation is not useful.
Do you get this error when you apply the patch to your project? If so, could you please provide some steps for how we can reproduce your problem.
Comment #27
chr.fritschAh sorry, @rensingh99. Your screenshot belongs to your comment 2 weeks ago. Now I get it. My fault 🤦🏻♂️
So I assume the screenshot shows the problem you had before applying the patch.
Comment #28
rensingh99 commented@chr.fritsch Yes Thank you
Comment #29
larowlanNo longer applies?
Comment #30
aleevas17 was re-rolled
Comment #31
alexpottWe need the test module to be Drupal 9 compat too.
Comment #33
alexpottAh we need #3096609: Allow contrib test modules to not need a core or core_version_requirement key because we copy the module out of the core directory in \Drupal\Tests\config\Functional\ConfigInstallProfileUnmetDependenciesTest - or we can add
core_version_requirement: '*'but let's hope that issue lands.Comment #34
alexpott#3096609: Allow contrib test modules to not need a core or core_version_requirement key landed so we're back to rtbc as the re-roll has been completed.
Comment #35
hchonovDo we have a test ensuring that if an optional configuration is overridden in the profile then it will be still installed correctly?
Comment #36
alexpott@hchonov check out ConfigInstallProfileOverrideTest - much overriding of all the thing going on there!
Comment #37
Percy101 commentedPatch applied cleanly
Comment #38
adam-delaney commentedPatch #31 fails to apply for Drupal 8.8.2
Comment #39
alexpott@adam-delaney you could safely ignore the changes to
core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.installbut this patch is targeting 8.9.x and 9.0.x and applies there just fine.Comment #40
catchThis makes me wary about an 8.9.x backport.
Patch looks good for 9.0.x though.
Comment #41
danielvezaSlightly unrelated, if we're having to call \Drupal::service('config.installer')->isSyncing() inside hook_module_preinstall, wouoldn't it make sense to add the $is_syncing param as we do for hook_install etc?
Happy to open a seperate issue for this.
Comment #42
alexpott@DanielVeza good idea. All the install and uninstall hooks should have this param and document the considerations.
Comment #43
danielvezaGreat. Opened #3118155: Standardize hook_module_preinstall to use $is_syncing parameter instead of direct service calls.
Comment #44
alexpott@catch thanks for review this. Re #40 - i think it is okay to put this in 9.0.x only but I think the benefits of putting this in 8.9.x outweigh the negatives. Just this is a tiny bit disruptive for profiles that have a module that installs default content where that default content is depended on by configuration it provides (i.e content block placements). But I think that this situation is extremely rare. Unlike the situation of profile configuration depending on optional configuration provided by modules it depends on. However I'd be happy if this fix makes it into any branch :)
Comment #45
catchWe need to document #44 in a change record and release note, regardless of whether this gets backported.
Comment #46
alexpottAdded a change record: https://www.drupal.org/node/3118908 and a release note.
Comment #48
catchCommitted aeae01b and pushed to 9.0.x. Thanks!
Moving to 8.9.x, I'm still not sure what I think about that.
Comment #49
xjmComment #50
chr.fritschDo we have any chance to get this into D8.9?
Comment #51
neslee canil pintoPatch for 8.9.x
Comment #52
alexpott@Neslee Canil Pinto the patch in #31 applies to 8.9.x and has been tested against it.
Comment #54
xjmWell it definitely doesn't belong against 9.1.x., so marking back to fixed against 9.0.x.
Comment #55
xjm