Closed saltednut closed 5 years ago
Just remembered that there is an event for Modules Installed otherwise config_rewrite
wouldn't even work. Oof! I wrote something similar to this 2 years ago. https://git.drupalcode.org/project/config_rewrite/blob/8.x-2.x/src/EventSubscriber/ConfigRewriteInstallSubscriber.php#L34
Gosh its all flooding back to me now I remember. Sam and I worked on a 2.x branch of config_rewrite that used this patch https://www.drupal.org/project/drupal/issues/2350111 - the eventsubscriber stuff is there. In 1.x we use a hook called hook_module_preinstall()
-- in order to make this work with modules asap, we could use hook_module_preinstall()
but sadly there's no theme equivalent to this hook that I can find.
Ok actually here's the theme hook, I think? https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_themes_installed/8.7.x
Example from shortcut should help, https://api.drupal.org/api/drupal/core%21modules%21shortcut%21shortcut.module/function/shortcut_themes_installed/8.7.x
So to recap:
Right now we'll implement hook_module_preinstall() and hook_themes_installed() to add this functionality to the existing functionality similar to what we do for install profiles here: https://git.drupalcode.org/project/scenarios/blob/8.x-4.x/scenarios.module#L58
Only difference being we'd feed a module name or theme name in.
In the future, we'd like to move over to a system where all extensions fire the same event when they get enabled and scenarios should use an event subscriber consistently across all types of extensions.
hook_modules_installed
was a better call, but hook_themes_installed
was the way to go here, see https://git.drupalcode.org/project/scenarios/commit/4daf46ca47f3ebd26ca4fa44f5d0de06fffad0df
One great thing is that all extensions can install configuration via
config/install
- it stands to reason that if that is the case, any extension could call itself a Scenario.The Scenarios module used in DF could listen for a key event to enable scenarios. Right now its demo content import is "listening" for only the profile installation occurrence via a hook we have added (and not successfully committed yet) to core. Invoke hook after a site install is complete
This works and we could add hooks or even events/listeners for module, theme and profile install occurrences. That might be the best, most stable, long term solution.
However, I have another idea that one could do with core in its current state that will help Modules and Themes declare themselves a scenario and act accordingly. We'd do this by defining a scenario yml file similar to the ACF catalogs like the one found here: https://github.com/acquia/acf/blob/master/acf_demo/modules/acf_demo_api/config/install/acf_catalog.catalog.acf_demo.yml - the scenarios module would listen for a config install and only act when a new "scenario" config popped in with info about things like where to find a CDF to import or what migrations need run.
The one issue with using config is that this doesn't really help install profiles. They will still likely be better off with a hook or an event listener that ensures everything they need installed is there before running the scenario enablement.
Otherwise the other ways we can ensure this will work is if: