diff --git a/packages/strapi-plugin-content-type-builder/controllers/validation/model-schema.js b/packages/strapi-plugin-content-type-builder/controllers/validation/model-schema.js index 68d4c10d1b..4ef58080b0 100644 --- a/packages/strapi-plugin-content-type-builder/controllers/validation/model-schema.js +++ b/packages/strapi-plugin-content-type-builder/controllers/validation/model-schema.js @@ -16,6 +16,7 @@ const createSchema = (types, relations, { modelType } = {}) => { .required('name.required'), description: yup.string(), draftAndPublish: yup.boolean(), + pluginOptions: yup.object(), connection: yup.string(), collectionName: yup .string() @@ -45,16 +46,13 @@ const createAttributesValidator = ({ types, modelType, relations }) => { } if (_.has(attribute, 'type')) { - return getTypeValidator(attribute, { types, modelType, attributes }) - .test(isValidKey(key)) - .noUnknown(); + return getTypeValidator(attribute, { types, modelType, attributes }).test( + isValidKey(key) + ); } if (_.has(attribute, 'target')) { - return yup - .object(getRelationValidator(attribute, relations)) - .test(isValidKey(key)) - .noUnknown(); + return yup.object(getRelationValidator(attribute, relations)).test(isValidKey(key)); } return typeOrRelationValidator; diff --git a/packages/strapi-plugin-content-type-builder/controllers/validation/relations.js b/packages/strapi-plugin-content-type-builder/controllers/validation/relations.js index 876bff0888..e6cdf31bea 100644 --- a/packages/strapi-plugin-content-type-builder/controllers/validation/relations.js +++ b/packages/strapi-plugin-content-type-builder/controllers/validation/relations.js @@ -51,5 +51,6 @@ module.exports = (obj, validNatures) => { .nullable(), targetColumnName: yup.string().nullable(), private: yup.boolean().nullable(), + pluginOptions: yup.object(), }; }; diff --git a/packages/strapi-plugin-content-type-builder/controllers/validation/types.js b/packages/strapi-plugin-content-type-builder/controllers/validation/types.js index bcb057de91..ba6d199aa8 100644 --- a/packages/strapi-plugin-content-type-builder/controllers/validation/types.js +++ b/packages/strapi-plugin-content-type-builder/controllers/validation/types.js @@ -36,6 +36,7 @@ const getTypeValidator = (attribute, { types, modelType, attributes }) => { .required(), configurable: yup.boolean().nullable(), private: yup.boolean().nullable(), + pluginOptions: yup.object(), ...getTypeShape(attribute, { modelType, attributes }), }); }; diff --git a/packages/strapi-plugin-content-type-builder/services/Components.js b/packages/strapi-plugin-content-type-builder/services/Components.js index 334d908345..c26e6b526f 100644 --- a/packages/strapi-plugin-content-type-builder/services/Components.js +++ b/packages/strapi-plugin-content-type-builder/services/Components.js @@ -24,6 +24,7 @@ const formatComponent = component => { description: _.get(info, 'description', ''), connection, collectionName, + pluginOptions: component.pluginOptions, attributes: formatAttributes(component), }, }; diff --git a/packages/strapi-plugin-content-type-builder/services/ContentTypes.js b/packages/strapi-plugin-content-type-builder/services/ContentTypes.js index 20a2d6e442..9a5d2931a7 100644 --- a/packages/strapi-plugin-content-type-builder/services/ContentTypes.js +++ b/packages/strapi-plugin-content-type-builder/services/ContentTypes.js @@ -49,6 +49,7 @@ const formatContentType = contentType => { name: getformattedName(contentType), description: _.get(info, 'description', ''), draftAndPublish: contentTypesUtils.hasDraftAndPublish({ options }), + pluginOptions: contentType.pluginOptions, connection, kind: kind || 'collectionType', collectionName, diff --git a/packages/strapi-plugin-content-type-builder/services/__tests__/__snapshots__/content-types.test.js.snap b/packages/strapi-plugin-content-type-builder/services/__tests__/__snapshots__/content-types.test.js.snap index 7c055c0b96..b17f621a1f 100644 --- a/packages/strapi-plugin-content-type-builder/services/__tests__/__snapshots__/content-types.test.js.snap +++ b/packages/strapi-plugin-content-type-builder/services/__tests__/__snapshots__/content-types.test.js.snap @@ -16,6 +16,11 @@ Object { "draftAndPublish": false, "kind": "singleType", "name": "My name", + "pluginOptions": Object { + "content-manager": Object { + "visible": true, + }, + }, "restrictRelationsTo": null, "visible": true, }, diff --git a/packages/strapi-plugin-content-type-builder/services/__tests__/content-types.test.js b/packages/strapi-plugin-content-type-builder/services/__tests__/content-types.test.js index e419547fd7..b6bd5f1e37 100644 --- a/packages/strapi-plugin-content-type-builder/services/__tests__/content-types.test.js +++ b/packages/strapi-plugin-content-type-builder/services/__tests__/content-types.test.js @@ -18,6 +18,11 @@ describe('Content types service', () => { options: { draftAndPublish: false, }, + pluginOptions: { + 'content-manager': { + visible: true, + }, + }, attributes: { title: { type: 'string', diff --git a/packages/strapi-plugin-content-type-builder/services/schema-builder/component-builder.js b/packages/strapi-plugin-content-type-builder/services/schema-builder/component-builder.js index 599fd364bc..58d6987032 100644 --- a/packages/strapi-plugin-content-type-builder/services/schema-builder/component-builder.js +++ b/packages/strapi-plugin-content-type-builder/services/schema-builder/component-builder.js @@ -52,6 +52,7 @@ module.exports = function createComponentBuilder() { .set(['info', 'name'], infos.name) .set(['info', 'icon'], infos.icon) .set(['info', 'description'], infos.description) + .set('pluginOptions', infos.pluginOptions) .setAttributes(this.convertAttributes(infos.attributes)); if (this.components.size === 0) { @@ -101,6 +102,7 @@ module.exports = function createComponentBuilder() { .set(['info', 'name'], infos.name) .set(['info', 'icon'], infos.icon) .set(['info', 'description'], infos.description) + .set('pluginOptions', infos.pluginOptions) .setAttributes(this.convertAttributes(newAttributes)); if (newUID !== uid) { diff --git a/packages/strapi-plugin-content-type-builder/services/schema-builder/content-type-builder.js b/packages/strapi-plugin-content-type-builder/services/schema-builder/content-type-builder.js index 0e599f5b98..8380dd8115 100644 --- a/packages/strapi-plugin-content-type-builder/services/schema-builder/content-type-builder.js +++ b/packages/strapi-plugin-content-type-builder/services/schema-builder/content-type-builder.js @@ -86,6 +86,7 @@ module.exports = function createComponentBuilder() { timestamps: true, draftAndPublish: infos.draftAndPublish || false, }) + .set('pluginOptions', infos.pluginOptions) .setAttributes(this.convertAttributes(infos.attributes)); Object.keys(infos.attributes).forEach(key => { @@ -188,6 +189,7 @@ module.exports = function createComponentBuilder() { .set(['info', 'name'], infos.name) .set(['info', 'description'], infos.description) .set(['options', 'draftAndPublish'], infos.draftAndPublish || false) + .set('pluginOptions', infos.pluginOptions) .setAttributes(this.convertAttributes(newAttributes)); return contentType; diff --git a/packages/strapi-plugin-content-type-builder/tests/components.test.e2e.js b/packages/strapi-plugin-content-type-builder/tests/components.test.e2e.js index de4a278f7d..d1b855b37d 100644 --- a/packages/strapi-plugin-content-type-builder/tests/components.test.e2e.js +++ b/packages/strapi-plugin-content-type-builder/tests/components.test.e2e.js @@ -52,9 +52,19 @@ describe('Content Type Builder - Components', () => { category: 'default', icon: 'default', name: 'Some Component', + pluginOptions: { + pluginName: { + option: true, + }, + }, attributes: { title: { type: 'string', + pluginOptions: { + pluginName: { + option: true, + }, + }, }, pic: { type: 'media', @@ -152,9 +162,19 @@ describe('Content Type Builder - Components', () => { description: '', connection: 'default', collectionName: 'components_default_some_components', + pluginOptions: { + pluginName: { + option: true, + }, + }, attributes: { title: { type: 'string', + pluginOptions: { + pluginName: { + option: true, + }, + }, }, pic: { type: 'media', @@ -212,6 +232,11 @@ describe('Content Type Builder - Components', () => { icon: 'default', name: 'New Component', attributes: {}, + pluginOptions: { + pluginName: { + option: false, + }, + }, }, }, }); @@ -236,6 +261,11 @@ describe('Content Type Builder - Components', () => { uid: 'default.some-component', schema: { name: 'New Component', + pluginOptions: { + pluginName: { + option: false, + }, + }, }, }, }); diff --git a/packages/strapi-plugin-content-type-builder/tests/content-types.test.e2e.js b/packages/strapi-plugin-content-type-builder/tests/content-types.test.e2e.js index df661694cd..3c0e4297ff 100644 --- a/packages/strapi-plugin-content-type-builder/tests/content-types.test.e2e.js +++ b/packages/strapi-plugin-content-type-builder/tests/content-types.test.e2e.js @@ -51,9 +51,19 @@ describe('Content Type Builder - Content types', () => { body: { contentType: { name: 'Test Collection Type', + pluginOptions: { + i18n: { + localized: true, + }, + }, attributes: { title: { type: 'string', + pluginOptions: { + i18n: { + localized: true, + }, + }, }, }, }, @@ -125,9 +135,19 @@ describe('Content Type Builder - Content types', () => { contentType: { kind: 'singleType', name: 'Test Single Type', + pluginOptions: { + i18n: { + localized: true, + }, + }, attributes: { title: { type: 'string', + pluginOptions: { + i18n: { + localized: true, + }, + }, }, }, }, diff --git a/test/__snapshots__/all.test.e2e.js.snap b/test/__snapshots__/all.test.e2e.js.snap index 44c6d6bcd7..48e7d68741 100644 --- a/test/__snapshots__/all.test.e2e.js.snap +++ b/test/__snapshots__/all.test.e2e.js.snap @@ -317,6 +317,11 @@ Object { "schema": Object { "attributes": Object { "title": Object { + "pluginOptions": Object { + "i18n": Object { + "localized": true, + }, + }, "type": "string", }, }, @@ -326,6 +331,11 @@ Object { "draftAndPublish": false, "kind": "collectionType", "name": "Test Collection Type", + "pluginOptions": Object { + "i18n": Object { + "localized": true, + }, + }, "restrictRelationsTo": null, "visible": true, }, @@ -365,6 +375,11 @@ Object { "schema": Object { "attributes": Object { "title": Object { + "pluginOptions": Object { + "i18n": Object { + "localized": true, + }, + }, "type": "string", }, }, @@ -374,6 +389,11 @@ Object { "draftAndPublish": false, "kind": "singleType", "name": "Test Single Type", + "pluginOptions": Object { + "i18n": Object { + "localized": true, + }, + }, "restrictRelationsTo": null, "visible": true, },