-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathindex.js
103 lines (92 loc) · 2.86 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import * as yup from "yup";
import { prefixPluginTranslations } from "@strapi/helper-plugin";
import pluginPkg from "../../package.json";
import pluginId from "./pluginId";
import Initializer from "./components/Initializer";
import middlewares from "./middlewares";
import Versions from "./components/Versions";
import CheckboxConfirmation from "./components/CheckboxConfirmation";
import mutateCTBContentTypeSchema from "./utils/mutateCTBContentTypeSchema";
import { getTrad } from "./utils";
import addColumnToTableHook from "./contentManagerHooks/addColumnToTable";
const name = pluginPkg.strapi.name;
export default {
register(app) {
app.addMiddlewares(middlewares);
app.registerPlugin({
id: pluginId,
initializer: Initializer,
isReady: false,
name,
});
},
bootstrap(app) {
app.injectContentManagerComponent("editView", "right-links", {
name: "Versions",
Component: Versions,
});
// Hook that adds a column into the CM's LV table
app.registerHook(
"Admin/CM/pages/ListView/inject-column-in-table",
addColumnToTableHook
);
const ctbPlugin = app.getPlugin("content-type-builder");
if (ctbPlugin) {
const ctbFormsAPI = ctbPlugin.apis.forms;
ctbFormsAPI.addContentTypeSchemaMutation(mutateCTBContentTypeSchema);
ctbFormsAPI.components.add({
id: "checkboxConfirmation",
component: CheckboxConfirmation,
});
ctbFormsAPI.extendContentType({
validator: () => ({
versions: yup.object().shape({
versioned: yup.bool(),
}),
}),
form: {
advanced() {
return [
{
name: "pluginOptions.versions.versioned",
description: {
id: getTrad(
"plugin.schema.versions.versioned.description-content-type"
),
defaultMessage: "Allow you to keep older versions of content",
},
type: "checkboxConfirmation",
intlLabel: {
id: getTrad(
"plugin.schema.versions.versioned.label-content-type"
),
defaultMessage: "Enable versioning for this Content-Type",
},
},
];
},
},
});
}
},
async registerTrads({ locales }) {
const importedTrads = await Promise.all(
locales.map((locale) => {
return import(`./translations/${locale}.json`)
.then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, pluginId),
locale,
};
})
.catch(() => {
return {
data: {},
locale,
};
});
})
);
return Promise.resolve(importedTrads);
},
};