System Information
- Strapi Version: 4.5.6
- Operating System: WSL2 (Ubuntu 22.04) running on Windows 11
- Database: sqlite
- Node Version: 18.12.1
- NPM Version: 9.2.0
- Yarn Version: 1.22.15
I want the content manager to auto-generate a slug
each time I create a new photo
entry from a POST /api/photos/
request, so I set up a lifecycle hook to do this. For some reason, it isn’t being called.
src/extensions/photo/content-types/photo/lifecycles.js
module.exports = {
async beforeCreate(event) {
const { data } = event.params;
data.slug = await strapi.plugin['content-manager'].services.uid.generateUIDField({
contentTypeUID: 'api::photo.photo',
field: 'slug',
data: event.params.data
});
}
}
I tried to set up another one in src/index.js
, but this didn’t work either.
src/index.js
module.exports = {
bootstrap({ strapi }) {
strapi.db.lifecycles.subscribe({
models: ['api::photo.photo'],
async beforeCreate(event) { /* exact same as above */ }
});
}
};
Am I overlooking something?