Config Modifiers
Register plugin's configModifiers
What is Config Modifiers?
configModifiers is an object of methods that will be called from Dashboard when updating the plugin for certain versions and allows the plugin to modify and change the config before updating the plugin.
This will allow the plugin to twist the config for their need, it can add new config keys, remove existing config keys or modify existing ones.
This will give you the ability to reduce your config breaking changes when you release your plugin, which means that users don't have to go to plugin configuration when they update and change/save the config if your plugin's config has any breaking changes.
For example, if you moved a config ref key from a place to another, or you changed the type/structure of a config ref key ex: from an Object to an Array of Objects Then you can fix the changes with configModifiers, and update the config dynamically and avoid crashing the plugin due to your config changes!
How does it work?
You can register a config modifier for each version you want, and Dashboard will run all the modifiers in order from the current installed version to the newest one in your configModifiers
Let's say a Dashboard has your plugin installed with version 2.3.0, and the user is updating from 2.3.0 to the latest version of your plugin 2.4.0 Dashboard will run your 2.4.0 modifier and pass the current user's config and expects an updated config Object to be returned
Example
A user have version 2.3.0 with the following config:
And in your new version 2.4.0 you have moved both keys username/password from the root config.username/config.password
to a new ref key credentials config.credentials.username/config.credentials.password
Here comes the configModifiers part You can bump your plugin version with minor bump instead of a major bump and your configModifiers will take care of fixing the config without requiring the user to do the manual work
In this case your configModifiers will look something like
After the user updates from ANY version older than your new 2.4.0, Dashboard will run the "2.4.0" modifier and update the config with the returned value
So the user's config will be updated from the returned value from your modifier and it should look like
Multiple modifiers
How to register?
You can register configModifiers from the main register() API for your plugin
Advanced example
Last updated
Was this helpful?