2021-01-22 17:57:15 +01:00
|
|
|
'use strict';
|
|
|
|
|
2021-06-08 10:39:45 +02:00
|
|
|
const { getService } = require('./utils');
|
2021-01-25 20:58:33 +01:00
|
|
|
|
2021-07-08 11:20:13 +02:00
|
|
|
module.exports = async strapi => {
|
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');
|
2021-05-10 11:24:45 +02:00
|
|
|
const { sectionsBuilder, actions, engine } = getService('permissions');
|
2021-03-25 14:59:44 +01:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
// Engine/Permissions
|
|
|
|
engine.registerI18nPermissionsHandlers();
|
|
|
|
|
|
|
|
// Hooks & Models
|
2021-08-03 11:22:57 +02:00
|
|
|
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-08-03 11:22:57 +02:00
|
|
|
const i18nModelUIDs = Object.values(strapi.contentTypes)
|
|
|
|
.filter(contentType => getService('content-types').isLocalizedContentType(contentType))
|
|
|
|
.map(contentType => contentType.uid);
|
|
|
|
|
|
|
|
if (i18nModelUIDs.length > 0) {
|
|
|
|
strapi.db.lifecycles.subscribe({
|
|
|
|
models: i18nModelUIDs,
|
|
|
|
async beforeCreate(event) {
|
|
|
|
await getService('localizations').assignDefaultLocale(event.params.data);
|
|
|
|
},
|
2021-02-16 12:08:35 +01:00
|
|
|
});
|
2021-08-03 11:22:57 +02:00
|
|
|
}
|
2021-03-25 12:18:40 +01:00
|
|
|
|
2021-08-03 11:22:57 +02:00
|
|
|
strapi.db.lifecycles.subscribe({
|
|
|
|
models: ['plugins::i18n.locale'],
|
2021-03-25 12:18:40 +01:00
|
|
|
|
|
|
|
async afterCreate() {
|
|
|
|
await getService('permissions').actions.syncSuperAdminPermissionsWithLocales();
|
|
|
|
},
|
|
|
|
|
|
|
|
async afterDelete() {
|
|
|
|
await getService('permissions').actions.syncSuperAdminPermissionsWithLocales();
|
|
|
|
},
|
|
|
|
});
|
2021-02-12 12:23:51 +01:00
|
|
|
};
|