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
Thanks for replying. I was expecting that it be relatively easy to manage overlay layers (not the base layers that are indeed controlled form the Leaflet More Maps module's settings page). That...
Layer management in Leaflet
for instance, to set up a layer for water basins and another for mining concessions... Are those tiles from a tile server, or some GeometryCollection in local file in json...
Layer management in Leaflet
We were able to add overlays and polygons to leaflet with a custom module as mentioned in https://github.com/backdrop-contrib/leaflet/issues/73#issuecomment-2907873081 with a combination of php...
Layer management in Leaflet