I am currently trying to get my modules to work properly. Extending the modules by adding Fields works great. I use several modules (e.g. "teaser") that extend a "container" which defines basic options like size.
This is my container, defining a "size" option:
module.exports = {
extend: 'apostrophe-widgets',
label: 'Container',
contextualOnly: true,
addFields: [{
name: 'contentBlock',
type: 'area',
label: 'Content Block',
}],
beforeConstruct: function(self, options) {
options.addFields = [{
name: 'size',
label: 'Modulbreite',
type: 'select',
choices: [{
label: 'Content width',
value: 'content-width'
},
{
label: 'Full width',
value: 'full-width'
}
],
required: true
}].concat(options.addFields || []);
}
};
And this is my teaser, extending the container:
module.exports = {
extend: 'container-widgets',
label: 'Teaser',
contextualOnly: false,
addFields: [
{
name: 'teasertext',
label: 'Text',
type: 'string',
textarea: true
},
{
name: 'teaserurl',
label: 'Link',
type: 'string',
required: true
},
{
name: 'image',
label: 'Teaser Image',
type: 'singleton',
widgetType: 'apostrophe-images',
options: {
limit: 1
},
required: true
}
]
};
Then I include the container in the page markup:
{{ apos.area(data.page, 'body', { widgets: { 'container': {} } }) }}
And the teaser in the container markup:
{{ apos.area(data.widget, 'contentBlock', { widgets: { 'teaser': {} } }) }}
The problem is that in some cases, I don't want to give the user the "size" option because the teaser could be nested in some other module that already defines the size. Therefore, I want to pass an argument for removing the "size" option. This does not work as I thought, but I don't know if this is even possible like this.
I tried to include a teaser in this case like this:
{{ apos.area(data.widget, 'contentBlock', { widgets: {
'teaser': {
removeFields: ['size']
}
} }) }}
Is this not possible or did I get something else wrong?
You cannot use removeFields
in the options passed to apos.area
because the schema of the widget is determined at startup time, for all widgets of that type.
However, you can extend
your teaser-widgets
module to make a simple-teaser-widgets
module that does use removeFields
to remove the size
field. Then you can put the widget type you want in each area and leave out the other.
index.js
for simple-teaser-widgets
is very simple indeed:
module.exports = {
extend: 'teaser-widgets',
label: 'Simple Teaser'
};