2021-01-22 17:57:15 +01:00
|
|
|
'use strict';
|
|
|
|
|
2021-02-15 11:24:28 +01:00
|
|
|
const { getService } = require('../../utils');
|
2021-01-25 20:58:33 +01:00
|
|
|
|
2021-02-16 14:36:11 +01:00
|
|
|
module.exports = async () => {
|
2021-04-21 15:32:30 +02:00
|
|
|
const { sendDidInitializeEvent } = getService('metrics');
|
2021-03-08 18:08:47 +01:00
|
|
|
const { decorator } = getService('entity-service-decorator');
|
2021-03-25 14:59:44 +01:00
|
|
|
const { initDefaultLocale } = getService('locales');
|
|
|
|
const { sectionsBuilder, actions, conditions, engine } = getService('permissions');
|
|
|
|
|
|
|
|
// Entity Service
|
2021-03-08 18:08:47 +01:00
|
|
|
strapi.entityService.decorate(decorator);
|
2021-03-08 16:39:39 +01:00
|
|
|
|
2021-03-25 14:59:44 +01:00
|
|
|
// Data
|
|
|
|
await initDefaultLocale();
|
|
|
|
|
|
|
|
// Sections Builder
|
|
|
|
sectionsBuilder.registerLocalesPropertyHandler();
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
await actions.registerI18nActions();
|
|
|
|
actions.registerI18nActionsHooks();
|
|
|
|
actions.updateActionsProperties();
|
|
|
|
|
|
|
|
// Conditions
|
|
|
|
await conditions.registerI18nConditions();
|
|
|
|
|
|
|
|
// Engine/Permissions
|
|
|
|
engine.registerI18nPermissionsHandlers();
|
|
|
|
|
|
|
|
// Hooks & Models
|
|
|
|
registerModelsHooks();
|
2021-04-21 15:32:30 +02:00
|
|
|
|
|
|
|
sendDidInitializeEvent();
|
2021-03-25 14:59:44 +01:00
|
|
|
};
|
2021-02-16 14:36:11 +01:00
|
|
|
|
2021-03-25 14:59:44 +01:00
|
|
|
const registerModelsHooks = () => {
|
2021-02-16 12:08:35 +01:00
|
|
|
Object.values(strapi.models)
|
2021-04-07 11:43:46 +02:00
|
|
|
.filter(model => getService('content-types').isLocalizedContentType(model))
|
2021-02-16 12:08:35 +01:00
|
|
|
.forEach(model => {
|
|
|
|
strapi.db.lifecycles.register({
|
|
|
|
model: model.uid,
|
|
|
|
async beforeCreate(data) {
|
2021-02-17 16:59:46 +01:00
|
|
|
await getService('localizations').assignDefaultLocale(data);
|
2021-02-16 12:08:35 +01:00
|
|
|
},
|
2021-02-12 12:23:51 +01:00
|
|
|
});
|
2021-02-16 12:08:35 +01:00
|
|
|
});
|
2021-03-25 12:18:40 +01:00
|
|
|
|
|
|
|
strapi.db.lifecycles.register({
|
|
|
|
model: 'plugins::i18n.locale',
|
|
|
|
|
|
|
|
async afterCreate() {
|
|
|
|
await getService('permissions').actions.syncSuperAdminPermissionsWithLocales();
|
|
|
|
},
|
|
|
|
|
|
|
|
async afterDelete() {
|
|
|
|
await getService('permissions').actions.syncSuperAdminPermissionsWithLocales();
|
|
|
|
},
|
|
|
|
});
|
2021-02-12 12:23:51 +01:00
|
|
|
};
|