| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Author : Nans / n4n5
If your plugin needs to save data, you have multiple choices :
To save data into the config, you can use predefined functions already created in AquilaCMS :
Here is a code example :
const { getConfig, setConfig } = require('../../../services/modules');
const info = require('../info.json').info; // used to have the plugin name
const myFunctionToGetData = async function(){
// .. do smthg
const config = await getConfig(info.name);
// .. do smthg
}
const myFunctionToSaveData = async function(theNewConfig){
// .. do smthg
const config = await setConfig(info.name, theNewConfig);
// .. do smthg
}
module.exports = {
myFunctionToGetData,
myFunctionToSaveData
};Legend :
- Note that these two functions are async
- Note that setConfig() returns the actual configuration
Maybe you want to directly save the data from the front to the database. It is possible with a special route :
POST /v2/module/setConfigIt is a POST route, the parameters are :
{
name: theNameOfThePlugin
config: theConfigToSave
}If you want to check the data before saving, it is possible with preHook before saving the configuration in Aquila.
When a configuration is saved, an event is emitted. You can catch this event to check the config before saving.
The event's name is changePluginConfig_ThePluginName. So you need to catch changePluginConfig_YourPluginName.
With ThePluginName => the name of the plugin being saved
With YourPluginName => the name of your plugin
Here is a code example :
In services/nameOfService.js
const infos = require('../info.json').info;
const aquilaEvents = require('../../../utils/aquilaEvents');
aquilaEvents.on(`changePluginConfig_${infos.name}`, (configToCheck) => {
configToCheck.config = {vide : true};
return configToCheck;
});Legend :
- Note that configToCheck is corresponding to { config : theConfig }
- ⚠️ Note that destructuring the object with ({config}) => {} will not work
Installation
Get started
Core reference
Themes
Images
Plugin Creation
Hook
Updating
Testing
| Back | FazBrowse Home | New Git URL |