Hi all,
I'm working on a couple of projects, porting them to Backdrop, and I ran into a bit of a unique challenge. It appears that the module I'm working on uses dynamic names when using variable_get(). To convert this to use config_get(), I need to put the default value into the .settings.json file as explained here. How should I approch this? The code in question looks like so:
$type_menus = variable_get('menu_options_' . $params['type'], array('main-menu' => 'main-menu'));
As far as I have read, JSON doesn't allow for wildcards. Has anyone else run into this? How did you solve it?
Comments
Yep, I've come across this before. Can't remember what module though...
The solution is to put all non-dynamic ('static' I guess) variables in your default config file as normal, then add the dynamic ones via
hook_install()
in your.install
file (usingconfig_set()
).For example:
my_module.settings.json:
or my_module.install:
Here's an example from the Save Draft module.