Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
hook_install()
cannot be used for content imports in modules because the module cannot rely on default config to be there if they are installed during config import.
Proposed resolution
Add a fallback config import event.
Remaining tasks
Finalise the approach.
Create a patch.
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#19 | 2914213-19.patch | 11.27 KB | jibran |
Comments
Comment #2
jibranWe can't do this until #2788777: Allow a site-specific profile to be installed from existing config is in.
Comment #3
jibranFixed c/p issue.
Comment #4
jibranComment #5
Alumei CreditAttribution: Alumei commentedBut isn't the problem either way, that the module has no assurance for the expected config to be present.
If the config that the module relies on in the subscriber is not present after config import, because It was deleted before the export, this would still fail, right?
Comment #6
Alumei CreditAttribution: Alumei commentedsry, was not my intention
Comment #7
Alumei CreditAttribution: Alumei commentedHow is this different from #2901418: Add hook_post_config_import_NAME after config import? To me it looks like both issues provide similar solutions.
Comment #8
jibranWe can add the check here whether the config is present or not.
This one will be fired after the module is installed and that one will tackle the situation after hook_update_N has run.
Comment #9
alexpottThere's yet another problem. We have no idea whether the content is valid. It is possible to have added a required field that during config import will be created before the content is created :(
Comment #10
gambryWasn't this issue meant to be a documentation task, according to #2788777: Allow a site-specific profile to be installed from existing config #114?
Comment #11
alexpott@gambry well we can do both. But I'm not sure this solution is correct and I know that the extra documentation is warranted.
Comment #12
jibranAny suggestions for moving forward?
Comment #13
gambryThis is just me talking aloud:
I'm not sure there is a simple way to go around this issue.
When a module with default config is installed NOT as part of config import, then implementing either #3 or #2901418: Add hook_post_config_import_NAME after config import fixes what this issue is about.
But as soon as its default config becomes part of the sync storage and the module is installed as part of the config import... everything can happen! And #3 or #2901418: Add hook_post_config_import_NAME after config import implementations may have invalid content.
And there is no way for the module shipping the original config to know what's going on. It may be a new required field, it may also be a pre-save function blocking the CRUD process under certain conditions, failing spectacularly.
Suggestion:
Why don't we make a clear separation between these two scenarios and we create a custom hook to run only after default configuration is imported during standard install process?
Then #2901418: Add hook_post_config_import_NAME after config import will cover most of the other scenarios.
A module
ABC
"extending" default configuration of moduleDEF
may require to re-implement the logic of itsDEF_default_config_imported()
hook (or call it directly) withinABC_post_config_import_NAME()
if - for example - they require that content to exists.My only doubt is if the scenario when ABC and DEF modules are installed through
config_installer
profile behaves for them like the standard install or the config import process.Comment #14
Alumei CreditAttribution: Alumei commentedI think this sound reasonable,
Comment #17
jibranComment #19
jibranHere is a reroll of #3 but it also added content registry service to make sure we keep track of created content. Thoughts?
Comment #21
jibranTBH, I have mixed feeling about this approach. We made a deliberate effort to remove all the uuid form the config this is going against that but then these are content uuids not config.
Comment #27
larowlanOn the basis of the proposed resolution this sounds like a feature request
Now drush supports deploy hooks is this something we want to continue with?
Comment #31
smustgrave CreditAttribution: smustgrave at Mobomo commentedIf still a valid request please reopen updating issue summary for D10 and up
Thanks everyone that worked on it!