As suggested at that github issue (lifecycle hooks not working in Collections with draft/publish-System · Issue #8329 · strapi/strapi · GitHub) I like to discuss my problem here.
I have my own slug field which is generated beforeCreate and beforeUpdate. With the introduction of the draft/publish-system my code was not working, because on publishing only the published_at field is present in data, because pressing the “publish”-button only puts this field. I came up with the solution to check if a mandatory field is present in the data-object. If yes the “save”-button was pressed, beacuase than all fields are in the data-object. So I do not have to make anaother query with params:id:
'use strict';
const slugify = require('slugify');
const { default: createStrapi } = require('strapi');
const mySlugify = (slug) => {
return (
slugify(slug, {
remove:/[*+~.(){}\[\]\\/'"!:@,]/g,
lower:true
})
);
};
/**
* Lifecycle callbacks for the `product` model.
*/
module.exports = {
lifecycles: {
async beforeCreate(data) {
if (data.orderno) {
if (!data.name_en) {
data.name_en = data.name_de;
}
data.slug_de = mySlugify(data.name_de + '-' + data.orderno);
data.slug_en = mySlugify(data.name_en + '-' + data.orderno);
}
},
async beforeUpdate (params,data) {
if (data.orderno) {
if (!data.name_en) {
data.name_en = data.name_de;
}
data.slug_de = mySlugify(data.name_de + '-' + data.orderno);
data.slug_en = mySlugify(data.name_en + '-' + data.orderno);
}
},
}
};
My problem is, that the data form is not refrehed immediatly after save, like at the first creating.
The changes are only shown after closing the form and opening it again.
Is there a way to refresh the shown data after updating?