This came up in the Zulip chat:
I want to mention setting defaults in a module's configuration form. That's what I started to do:
'#description' => t('Additional body class for pages with a Tocbot block.<br /> Default: <code>toc-is-active</code>'),
Instead, I'd like to make use of
'#default_value' => $config->get('tocbot_extrabodyclass'), for the display of defaults. Is it possible, and could someone post an example? ... ...I'd like to display default settings in the description text of the setting. ...Is there a way to get the value for the description text from (in my case)
tocbot/config/tocbot.settings.json? AFAIK, a changed value would be from the config file in the Backdrop active config directory instead.
If there isn't a obvious approach, I'm however fine to hardcode the default values in the description texts. I guess they won't change so often.
@olafgrabienski The only place default values exist is in your module's
config/*.jsonfile. Once the module's installed and that file's copied into the active config, it can change. I don't believe there's any (easy) way to read from your module's default config file, so hard-coding is the only way (and I don't think it's the wrong way either - default values are hard-coded in the default config file, so they can be hard-coded in a description text too, just remember to update both places should they ever change).
Thanks for your feedback, @BWPanda! Good to know that hardcoding the values isn't the 'wrong' way in this case. Re "remember to update both places". Actually, there are three places as there is also the install file. And my module has a lot of config values. Unfortunately, all three places are in slightly different format. But as you say: should they ever change ...
Seems that we need a
$config->getDefault('what.have.you')...could be a feature request @olafgrabienski :wink: