2021-01-29 10:08:58 +01:00
|
|
|
import React from 'react';
|
2021-02-05 11:56:05 +01:00
|
|
|
import { get } from 'lodash';
|
2021-01-26 16:18:26 +01:00
|
|
|
import * as yup from 'yup';
|
2021-01-22 17:57:15 +01:00
|
|
|
import pluginPkg from '../../package.json';
|
2021-01-26 10:31:50 +01:00
|
|
|
import middlewares from './middlewares';
|
2021-01-22 17:57:15 +01:00
|
|
|
import pluginId from './pluginId';
|
|
|
|
import pluginLogo from './assets/images/logo.svg';
|
|
|
|
import trads from './translations';
|
2021-01-28 11:33:37 +01:00
|
|
|
import { getTrad } from './utils';
|
2021-02-05 17:41:12 +01:00
|
|
|
import pluginPermissions from './permissions';
|
2021-02-04 16:49:03 +01:00
|
|
|
import CheckboxConfirmation from './components/CheckboxConfirmation';
|
2021-01-28 11:33:37 +01:00
|
|
|
import SettingsPage from './containers/SettingsPage';
|
2021-02-05 17:41:12 +01:00
|
|
|
import sanitizeCTBContentTypeSchema from './utils/sanitizeCTBContentTypeSchema';
|
|
|
|
import LOCALIZED_FIELDS from './utils/localizedFields';
|
2021-01-22 17:57:15 +01:00
|
|
|
|
|
|
|
export default strapi => {
|
|
|
|
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
|
|
|
|
2021-01-26 10:31:50 +01:00
|
|
|
middlewares.forEach(middleware => {
|
|
|
|
strapi.middlewares.add(middleware);
|
|
|
|
});
|
|
|
|
|
2021-01-22 17:57:15 +01:00
|
|
|
const plugin = {
|
|
|
|
description: pluginDescription,
|
|
|
|
icon: pluginPkg.strapi.icon,
|
|
|
|
id: pluginId,
|
|
|
|
isReady: true,
|
|
|
|
isRequired: pluginPkg.strapi.required || false,
|
|
|
|
mainComponent: null,
|
|
|
|
name: pluginPkg.strapi.name,
|
|
|
|
pluginLogo,
|
|
|
|
preventComponentRendering: false,
|
2021-01-28 11:33:37 +01:00
|
|
|
settings: {
|
|
|
|
global: {
|
|
|
|
links: [
|
|
|
|
{
|
|
|
|
title: {
|
|
|
|
id: getTrad('plugin.name'),
|
2021-01-29 10:08:58 +01:00
|
|
|
defaultMessage: 'Internationalization',
|
2021-01-28 11:33:37 +01:00
|
|
|
},
|
2021-01-29 10:08:58 +01:00
|
|
|
name: 'internationalization',
|
|
|
|
to: `${strapi.settingsBaseURL}/internationalization`,
|
2021-01-28 11:33:37 +01:00
|
|
|
Component: () => <SettingsPage />,
|
2021-02-08 13:47:43 +01:00
|
|
|
permissions: pluginPermissions.accessMain,
|
2021-01-28 11:33:37 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2021-01-22 17:57:15 +01:00
|
|
|
trads,
|
2021-01-26 16:18:26 +01:00
|
|
|
boot(app) {
|
|
|
|
const ctbPlugin = app.getPlugin('content-type-builder');
|
|
|
|
|
|
|
|
if (ctbPlugin) {
|
2021-01-27 09:32:54 +01:00
|
|
|
const ctbFormsAPI = ctbPlugin.apis.forms;
|
2021-02-05 17:41:12 +01:00
|
|
|
ctbFormsAPI.addContentTypeSchemaSanitizer(sanitizeCTBContentTypeSchema);
|
2021-02-04 16:49:03 +01:00
|
|
|
ctbFormsAPI.components.add({ id: 'checkboxConfirmation', component: CheckboxConfirmation });
|
2021-01-26 16:50:54 +01:00
|
|
|
|
2021-01-27 09:32:54 +01:00
|
|
|
ctbFormsAPI.extendContentType({
|
|
|
|
validator: () => ({
|
2021-02-04 14:18:54 +01:00
|
|
|
i18n: yup.object().shape({
|
|
|
|
localized: yup.bool(),
|
|
|
|
}),
|
2021-01-27 09:32:54 +01:00
|
|
|
}),
|
2021-01-26 16:50:54 +01:00
|
|
|
form: {
|
|
|
|
advanced() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
{
|
2021-02-04 14:18:54 +01:00
|
|
|
name: 'pluginOptions.i18n.localized',
|
2021-02-05 11:56:05 +01:00
|
|
|
description: {
|
|
|
|
id: getTrad('plugin.schema.i18n.localized.description-content-type'),
|
|
|
|
},
|
2021-02-04 16:49:03 +01:00
|
|
|
type: 'checkboxConfirmation',
|
2021-02-05 11:56:05 +01:00
|
|
|
label: { id: getTrad('plugin.schema.i18n.localized.label-content-type') },
|
2021-01-26 16:50:54 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-02-05 17:41:12 +01:00
|
|
|
ctbFormsAPI.extendFields(LOCALIZED_FIELDS, {
|
|
|
|
validator: () => ({
|
|
|
|
i18n: yup.object().shape({
|
|
|
|
localized: yup.bool(),
|
2021-02-04 14:18:54 +01:00
|
|
|
}),
|
2021-02-05 17:41:12 +01:00
|
|
|
}),
|
|
|
|
form: {
|
|
|
|
advanced({ contentTypeSchema, forTarget, type, step }) {
|
|
|
|
if (forTarget !== 'contentType') {
|
|
|
|
return [];
|
|
|
|
}
|
2021-02-05 11:56:05 +01:00
|
|
|
|
2021-02-05 17:41:12 +01:00
|
|
|
const hasI18nEnabled = get(
|
|
|
|
contentTypeSchema,
|
|
|
|
['schema', 'pluginOptions', 'i18n', 'localized'],
|
|
|
|
false
|
|
|
|
);
|
2021-02-05 11:56:05 +01:00
|
|
|
|
2021-02-05 17:41:12 +01:00
|
|
|
if (!hasI18nEnabled) {
|
|
|
|
return [];
|
|
|
|
}
|
2021-02-05 11:56:05 +01:00
|
|
|
|
2021-02-05 17:41:12 +01:00
|
|
|
if (type === 'component' && step === '1') {
|
|
|
|
return [];
|
|
|
|
}
|
2021-02-05 11:56:05 +01:00
|
|
|
|
2021-02-05 17:41:12 +01:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'pluginOptions.i18n.localized',
|
|
|
|
description: {
|
|
|
|
id: getTrad('plugin.schema.i18n.localized.description-field'),
|
2021-02-05 11:56:05 +01:00
|
|
|
},
|
2021-02-05 17:41:12 +01:00
|
|
|
type: 'checkbox',
|
|
|
|
label: { id: getTrad('plugin.schema.i18n.localized.label-field') },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
];
|
2021-01-26 16:18:26 +01:00
|
|
|
},
|
2021-02-05 17:41:12 +01:00
|
|
|
},
|
|
|
|
});
|
2021-01-26 16:18:26 +01:00
|
|
|
}
|
|
|
|
},
|
2021-01-22 17:57:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return strapi.registerPlugin(plugin);
|
|
|
|
};
|