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
[DX] Allow theme_get_setting()
to return a default value - like settings_get()
and update_variable_get()
do
#6107
Comments
config_get()
and theme_get_setting()
to return a default value (like settings_get()
and update_variable_get()
do)config_get()
and theme_get_setting()
to return a default value - like settings_get()
and update_variable_get()
do
...actually, I would argue that for consistency, I would prefer it if we introduced a new function called
|
I've just filed the first of
|
...actually, I think I better slit the 3rd item into its own separate issue 🤔 |
config_get()
and theme_get_setting()
to return a default value - like settings_get()
and update_variable_get()
dotheme_get_setting()
to return a default value - like settings_get()
and update_variable_get()
do
I think those two functions don't have a default parameter because their defaults are set in files. As for renaming I'd say this PR would complicate rather than help TBH. |
Right. That default would be useful in the cases when the module that this config file belongs to is being installed, or when reverting the config to defaults. I would still like to be able to specify a default config value programmatically, to act as a fallback if the config value has been deleted (for whatever reason). But I agree that that would be a nice-to-have. Lets discuss that further in #6108. |
And that is what I don't like and would like to see changed. I still want to preserve the ability to specify defaults via the .info file (for backwards compatibility too), but I don't want that to be an absolute requirement. Perhaps I should have filed a separate META before raising this, but here's the DX I had as I was trying to do something simple as adding a few settings to an existing theme:
So what seemd like a simple and relatively straight-forward task, ended being quite a few wasteful minutes of my life, some serious head-scratching, and the realization that we have unnecessary Backdrop-isms in place that make for a worse DX. I just expected things to "simply work"! So this issue here is the begining of an attempt to fix a few of things that as a developer I expect:
I hope that the above helps clarify the drive behind this request @docwilmot ...it wasn't simply me going through code and wanting to change/rename things - I actually tried to do something relatively simple that turned out to be super-tedious and annoying. |
(I mean I would like to see this implemented.) |
Then all functions that could return NULL be allowed to have a default!!
I'm being silly above but I think the whole point of putting config defaults in files was to make them portable, moving them back to code would be a grand step backwards, I'm sure we'd agree. So if these configs already have defaults on files, doesnt really make sense to me to create an opportunity to confuse things by having two possible defaults. If the function returns NULL it means you forgot to add a default file, and you should fix that. Not change the whole function. Maybe just me though. |
Someday the minimum PHP will be 7.4 and then we can just use |
I have to say that I agree with @docwilmot on this whole discussion. |
The That said, without the proposed change, the code to use is not much more complex. |
When trying to set up a settings form for a theme (using
HOOK_form_system_theme_settings_alter()
in atheme-settings.php
file), I very often find myself doing something like this:I would like to be able to do the following instead:
In other words, change the function to include a 3rd, optional
$default
parameter so that it istheme_get_setting($setting_name, $theme = NULL, $default = NULL)
.Similarly, I would like to be able to do that with
config_get()
, so change it to this:config_get($config_file, $option = NULL, $default = NULL)
.The text was updated successfully, but these errors were encountered: