1.0.1 • Published 5 years ago
@flaivour/apostrophe-enhancements v1.0.1
module
ApostropheCMS 2 module which brings extended features to core modules
Well, ApostropheCMS is really great, but who does not want new features as fresh as beers in the freezer? 🍺
Installation
Install module dependency
npm i --save @flaivour/apostrophe-enhancements
Declare it in apostrophe modules
// Modules declaration into `app.js`
modules: {
'@flaivour/apostrophe-enhancements': {}
}
That's it, module is ready 🎉
Features
Pieces insert conditions
Provide a way to declare conditions that new pieces must match to be inserted. These can be declared in addConditions
property of piece options.
// In declaration of module extending `apostrophe-pieces`
beforeConstruct: (self, options) => {
options.addFields = [
{
name: 'price',
label: 'Price',
type: 'integer',
required: true
}
].concat(options.addFields || [])
// Provide an array of conditions that should be match at insertion
options.addConditions = [
{
label: 'price should be a valid number greater than 0',
checking: (piece) => Number.isInteger(piece.price) && piece.price > 0
}
].concat(options.addConditions || [])
}
addConditions
is an array of conditions, taking form of objects containing at least a matching
property. This last is a function that is going to be called in beforeSave
with the insertion candidate piece. It must return a boolean, used to defined if condition is or not validated.
License
This is released under the MIT License.
1.0.1
5 years ago