This came up in the Zulip chat:
@olafgrabienski
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.
@BWPanda
@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).
@olafgrabienski
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 ...
@klonos
Seems that we need a
$config->getDefault('what.have.you')...could be a feature request @olafgrabienski :wink:
Recent comments
Coming from Drupal, I would recommend using the shop system Commerce rather than Ubercart for the features you’re looking for. It has already been ported to Backdrop CMS. General...
How to monetize a Backdrop site
When logged in: On a page with a path prefix it shows the language of the prefix. On the front page if I add the path prefix it shows the language of that prefix...
Language negotiation only working when logged in
Hi! The description is still very vague and lacks step-by-step instructions on how to reproduce. It doesn't include the version of Backdrop either, nor a list of contrib modules you are using...
Problems with HTML content and text formats