-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Give modules the ability to modify application config after their own co... #4505
Give modules the ability to modify application config after their own co... #4505
Conversation
Ref #3823 |
This is another attempt at the remove config keys issue. It feels like a fairly clean solution. Comments please. |
@@ -89,7 +84,8 @@ public function attach(EventManagerInterface $events) | |||
} | |||
|
|||
$this->callbacks[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, array($this, 'onLoadModule')); | |||
$this->callbacks[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULES, array($this, 'onLoadModulesPost'), -1000); | |||
$this->callbacks[] = $events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'onMergeConfig'), 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a BC break.
It looks pretty solid to me, but I fear you broke BC with your new mergeConfig event. |
…fig keys to be deleted
@prolic I've thought about this more, and reworked it a little. It's simpler now, and I don't think there are any BC breaks. ModuleManager test suite passes only with changes to the number of event listeners (because there is one new one). In ConfigListener I also changed the name of the |
good for me |
On Monday, May 20, 2013, Tim Roediger wrote:
This is a no-go, as any listener on the previous event name will no longer
Matthew Weier O'Phinney |
@weierophinney sorry, I didn't express myself properly. I haven't changed any event names, as you say, that would certainly be a BC break. This is what I have done: Before: All I have changed is the method name to better reflect the event it is attached to. |
@superdweebie This looks good -- essentially, all you're doing is triggering an additional event, and modules can hook into that in order to change the config if desired -- is that correct? Can you write up a sample showing how this would be done, and how it solves the "I want to remove a config key dynamically" problem? That way, those searching and landing here will know how it works, plus we have something we can copy into the docs. Once I see that, I'll merge. |
Some docs... This PR introduces a new ModuleManager Event named CONFIG_MERGE. It is triggered by
The CONFIG_MERGE event is triggered after all application configuration files from all sources have been loaded, including module configuration
To alter the merged application config before it is used or cached, attach to CONFIG_MERGE at a lower priority. eg:
Note that if a cached config is used by ModuleManager then CONFIG_MERGE will not be triggered. |
If you're reading this thread on email, I've edited the previous message to fix some typos. |
👍 This is pretty much exactly what I had in mind for a solution. Much more explicit than the other strategy, I like it. |
Give modules the ability to modify application config after their own co...
This is now merged; I'm working on an "advanced configuration" tutorial that will document this new feature currently, and will reference this issue when I post the pull request for it. |
Thanks @weierophinney and @EvanDotPro. It's nice to have this one resolved, and with a good clean solution too. |
…/resolve-3823 Give modules the ability to modify application config after their own co...
...nfig is merged in (including the ability to remove keys)