diff --git a/index.js b/index.js index 3408af95..bc7b1888 100644 --- a/index.js +++ b/index.js @@ -28,6 +28,60 @@ module.exports = { self.enableBrowserData(); }, + handlers(self) { + return { + 'apostrophe:modulesRegistered': { + setContextOperations() { + const excludedExportTypes = []; + const excludedImportTypes = []; + for (const mod of Object.values(self.apos.modules)) { + if (!self.apos.instanceOf(mod, '@apostrophecms/doc-type')) { + continue; + } + + if (mod.options.importExport?.export === false) { + excludedExportTypes.push({ + type: { + $ne: mod.__meta.name + } + }); + } + + if (!mod.options.singleton || mod.options.importExport?.import === false) { + excludedImportTypes.push({ + type: { + $ne: mod.__meta.name + } + }); + } + } + + const exportOperation = { + action: 'import-export-export', + context: 'update', + label: 'aposImportExport:export', + modal: 'AposExportModal', + props: { + action: 'import-export-export' + }, + if: { $and: excludedExportTypes } + }; + const importOperation = { + action: 'import-export-import', + context: 'update', + label: 'aposImportExport:import', + modal: 'AposImportModal', + if: { $and: excludedImportTypes }, + canCreate: true, + canEdit: true + }; + + self.apos.doc.addContextOperation(exportOperation); + self.apos.doc.addContextOperation(importOperation); + } + } + }; + }, methods, apiRoutes }; diff --git a/modules/@apostrophecms/import-export-doc-type/index.js b/modules/@apostrophecms/import-export-doc-type/index.js deleted file mode 100644 index be537721..00000000 --- a/modules/@apostrophecms/import-export-doc-type/index.js +++ /dev/null @@ -1,31 +0,0 @@ -const excludedTypes = []; - -module.exports = { - improve: '@apostrophecms/doc-type', - - init(self) { - const operation = { - action: 'import-export-export', - context: 'update', - label: 'aposImportExport:export', - modal: 'AposExportModal', - props: { - action: 'import-export-export' - } - }; - - if (self.options.importExport?.export === false) { - excludedTypes.push({ - type: { - $ne: self.__meta.name - } - }); - } - - if (excludedTypes.length) { - operation.if = { $and: excludedTypes }; - } - - self.apos.doc.addContextOperation(operation); - } -};