Lifecycles not firing in content-type

System Information
  • Strapi 4.1.0:
  • Macos 12.2:
  • MySQL 8.0.28:
  • Node v14.17.0:
  • NPM v8.3.0:
  • Yarn v1.22.17:

I’m trying to use the basic slugify code to auto-create a slug (I’m not using a UUID because I want to have a shared slug value or all locales).

In ./src/api/post/content-types/post/lifecycles.js, I have the following code:

const slugify = require("slugify");

module.exports = {
  beforeCreate(event) {
    const { data } = event.params;
    console.log('hi before')
    if (data.title) {
      data.slug = slugify(data.title, { lower: true });
    }
  },
  beforeUpdate(event) {
    const { data } = event.params;
    console.log('hi before')

    if (data.title) {
      data.slug = slugify(data.title, { lower: true });
    }
  },
};

Nothing fires when I interact with the post fields in the Content Manager. Has anyone else run into this in v4?

Does it trigger via the API?

I have done the same in v4 and it works for all of REST, graphql, Content Manager.

So sorry that I never updated this thread. I may be remembering it wrong, but I thought that the lifecycles fired in React in the browser in v3. In v4, I had been checking the console for the browser the entire time, rather the looking in the terminal running Strapi. The lifecycles work just fine. Thank you for checking in!