Skip to content

Commit 298372b

Browse files
committed
FEATURE: Load the plugin in all modules with Neos 8.3 and prevent duplicate registration
1 parent 275d46e commit 298372b

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

Configuration/Settings.Neos.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ Neos:
3333
- 'UI.NodeVariantCreationDialog.createAndCopy'
3434
- 'CR.Nodes.unfocus'
3535

36+
moduleConfiguration:
37+
# This setting will register the plugin with all backend modules which is only supported in Neos 8.3+
38+
additionalResources:
39+
javaScripts:
40+
Shel.Neos.CommandBar: 'resource://Shel.Neos.CommandBar/Public/Module.js'
41+
styleSheets:
42+
Shel.Neos.CommandBar: 'resource://Shel.Neos.CommandBar/Public/Module.css'
43+
3644
modules:
45+
# These settings are for Neos 8.2 and below as the global additionalResources setting is not supported yet
46+
# A check in the plugin code will prevent the plugin from being loaded twice
3747
administration:
3848
submodules:
3949
users:

packages/module-plugin/src/index.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ if (process.env.NODE_ENV !== 'production') {
88
require('preact/debug');
99
}
1010

11-
// Register & add the debug web component, tagName and attributes are automatically read from the component
12-
register(App, null, null, App.options);
11+
function initializeApp() {
12+
// Prevent registering the custom element twice
13+
if (window['SHEL_NEOS_COMMANDBAR_INITIALIZED']) return;
14+
window['SHEL_NEOS_COMMANDBAR_INITIALIZED'] = true;
15+
16+
// Register & add the debug web component, tagName and attributes are automatically read from the component
17+
register(App, null, null, App.options);
1318

14-
window.addEventListener('neoscms-i18n-initialized', () => {
1519
// Get the top bar left container and create a custom element to render the command bar into
1620
const topBarLeft = document.querySelector('.neos-top-bar-left');
1721
const pluginContainer = document.createElement('command-bar-container');
@@ -24,4 +28,11 @@ window.addEventListener('neoscms-i18n-initialized', () => {
2428
pluginContainer.setAttribute('styleuri', commandBarStyleTag.href);
2529

2630
topBarLeft.appendChild(pluginContainer);
27-
});
31+
}
32+
33+
// If the api is already initialized, initialize the app as the event listener wouldn't be called anymore
34+
if (window.NeosCMS?.I18n?.initialized) {
35+
initializeApp();
36+
} else {
37+
window.addEventListener('neoscms-i18n-initialized', initializeApp);
38+
}

0 commit comments

Comments
 (0)