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/*.json
file. 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
Hello, @yorkshirepudding! Thanks a lot, I got it, all sorted out.
My layout template (layout--blog.tpl.php) doesn't work
Hi @Gnome and welcome to Backdrop When I create custom layout templates I put them in /layouts/custom/my_layout Note: you can split modules and layouts between contrib and custom...
My layout template (layout--blog.tpl.php) doesn't work
This post explains how to do this in Drupal 7. In Backdrop, File Entity is already part of core. You will need to download and install module Views Field View. https://drupal.stackexchange...
I Need to Display an Image in a View that was Uploaded to a Webform