I’m still figuring out this new v4 way. But one think I would like to know is, how can I auto-create a content type from a generate plugin.
Example, I generate a plugin call “cheer”. Now I want that plugin to create a model call “cheer” so that I can control the model, route, controllers all within the plugin folders itself.
Here’s how my folder structure is :-
plugins/cheer/server/index.js
'use strict';
const register = require('./register');
const bootstrap = require('./bootstrap');
const destroy = require('./destroy');
const config = require('./config');
const controllers = require('./controllers');
const routes = require('./routes');
const services = require('./services');
const contentTypes = require('./content-types');
module.exports = {
register,
bootstrap,
destroy,
config,
controllers,
routes,
services,
contentTypes,
policies: {},
middlewares: {},
};
plugins/cheer/server/content-types/index.js
const contentTypeCheer = require('./cheer');
module.exports = {
'cheer': contentTypeCheer, // should re-use the singularName of the content-type
};
plugins/cheer/server/content-types/cheer/index.js
module.exports = {
info: {
tableName: 'content-type',
singularName: 'cheer', // kebab-case mandatory
pluralName: 'cheers', // kebab-case mandatory
displayName: 'Cheer',
description: 'Content type for cheer plugin.',
kind: 'collectionType'
},
options: {
draftAndPublish: false,
},
pluginOptions: {
'content-manager': {
visible: true
},
'content-type-builder': {
visible: true
}
},
attributes: {
"Type": {
"type": "string",
"required": true,
"unique": true
},
"Icon": {
"allowedTypes": [
"images"
],
"type": "media",
"multiple": false,
"required": true
}
}
};
I followed this structure based on this documentation Server API - Strapi Developer Docs , but when I try to run “strapi develop”, I got error “TypeError: Cannot set property ‘plugin’ of undefined”.
What did I do wrong?