You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/10-Advanced/01-plugin-development.md
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -510,6 +510,42 @@ Default value of activationOrder for most plugins is `0`. Plugins with higher ac
510
510
511
511
To ensure that plugin activates before some other plugins set `activationOrder` to negative value.
512
512
513
+
## Making plugin global
514
+
515
+
Each plugin should define a scope: resource-level or global level.
516
+
* Resource-level plugins should be used when plugin instance works only with one resource config or it's fields. Instances of resource-scope plugins should be installed into "plugins' field of resource config.
517
+
* All other plugins should be global-scoped. Such plugins are installed to `globalPlugins` of root adminforth config. They might modify configs of many resources like default AuditLog plugin or use several database resources to store data like default Agent plugin.
518
+
519
+
To make your plugin global, you need to use `pluginsScope:'global'` and `modifyGlobalConfig` instead of `modifyResourceConfig`
@@ -290,13 +290,21 @@ class AdminForth implements IAdminForth {
290
290
activatePlugins(){
291
291
afLogger.trace('🔌🔌🔌 Activating plugins');
292
292
constallPluginInstances=[];
293
+
constglobalPlugins=this.config.globalPlugins||[];
293
294
for(letresourceofthis.config.resources){
294
295
afLogger.trace(`🔌 Checking plugins for resource: ${resource.resourceId}`);
295
296
for(letpluginInstanceofresource.plugins||[]){
296
297
afLogger.trace(`🔌 Found plugin: ${pluginInstance.constructor.name} for resource ${resource.resourceId}`);
298
+
if(pluginInstance.pluginsScope==='global'){
299
+
thrownewError(formatHugePluginError(`Please move plugin ${pluginInstance.constructor.name} instance to index.ts config.globalPlugins array.
300
+
Details: Previously adminforth had only resource-level plugins. To keep project structure clean, in recent version of adminforth we introduced globalPlugins.
301
+
Global plugins are installed on whole application and not only one resource (like agent, audit logs etc)
0 commit comments