FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Plugin Save · AquilaCMS/AquilaCMS Wiki · GitHub

This repository was archived by the owner on Oct 9, 2025. It is now read-only.
/ AquilaCMS Public archive

Plugin Save

MaelVB edited this page Jul 30, 2021 · 2 revisions

Plugin - Save data

Author : Nans / n4n5


Save data

If your plugin needs to save data, you have multiple choices :

  • Add a Schema to Mongo
  • Save data in a file
  • Save data in config attribute in the plugin data

Save data in config

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

Save from the front

Maybe you want to directly save the data from the front to the database. It is possible with a special route :

POST /v2/module/setConfig

It is a POST route, the parameters are :

{
    name: theNameOfThePlugin
    config: theConfigToSave
}

Check data before saving

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

Wiki pages Pages 43

Clone this wiki locally


Back | FazBrowse Home | New Git URL