New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow plugin configs to override settings more automagically #1096
Comments
I'd argue that this should be the default behavior with plugin settings. It would also be nice if there were a way to defineSettings directly in your
You can clean this up a bit, but it's still a lot of boilerplate that would be a nice default:
|
This would be really nice, so that we could override anything on a per-environment basis. If this was baked into the Craft 3 |
I'm a big fan of this. |
I think the biggest win here is predictability for plugin users - knowing they can always set any setting via config, regardless of how the plugin is authored. |
Even more useful would be if it could tell you that the setting was being overridden by the config file, the way Craft does This would probably need to be on the Settings model however |
Some kind of Craft provided a way to bottleneck and standardize all of this would be really helpful. Plugin developers wouldn't have to reinvent the wheel, and all plug-ins would operate in an understood and predictable manner |
Agreed, this lets plugin authors display that settings are being overridden when displaying the CP field. Currently authors seem to implement this themselves for every plugin. |
+1! |
Slipped this in over the weekend, along with lots of other changes to the Config service. Going forward, all plugins that want to have settings will need to create a settings model and instantiate it with a protected This is a breaking change for plugins that were previously providing default values in Here’s an example of how our Element API plugin was affected by the changes, if that helps: craftcms/element-api@dd65ee4 |
I assume that a |
@khalwat, yeah there's just no need to set your defaults in the |
Geez, @brandonkelly said it right there in his original comment, too. I don't know how I missed that. @timkelty I'll probably still include the The one thing this doesn't solve is a plugin being able to report when a setting is overriding something in the db via a |
@khalwat Craft doesn’t define the HTML for the CP plugin settings; plugins do. So it would be up to the plugin to add those warnings if they wanted. Plugins can find which keys the config is defining like so: $overrideKeys = array_keys(Craft::$app->config->getConfigFromFile('pluginhandle')); or it might make more sense to get it directly from your settings template: {% set overrideKeys = craft.app.config.getConfigFromFile('pluginhandle')|keys %} |
Yeah the macro I've been using in the past is:
I'll figure out how to adapt it once it rolls out in beta 8 |
One caveat to be aware of though – if a setting is defined in the config file, the file’s value is going to override the DB-stored value, so your plugin (including its settings page) will never know what the actual DB-stored value is.. This is also the case when editing volume settings in the CP, if you override them in |
It seems a common pattern to define all plugin configuration as "settings" (in the db, configurable though cp), but have the all be overridable via a plugin config file.
It's easy enough to do, but I think it would be nice if this was either: the default (my preference), or just easier to flip on.
Currently I do something like:
But it would be great if I could just set:
Or instead of true you could even set an array of keys to allow overriding for.
The text was updated successfully, but these errors were encountered: