halo/docs
John Niang a94596a9f8
Add support for publishing events among plugins (#6081)
#### What type of PR is this?

/kind feature
/area core
/area plugin

#### What this PR does / why we need it:

This PR enhance usage of SharedEvent annotation to add support for publishing events among plugins.

#### How to test?

1. Clone repository https://github.com/halo-dev/plugin-starter
2. Change build.gradle as following:

	```gradle
	dependencies {
	    implementation platform('run.halo.tools.platform:plugin:2.17.0-SNAPSHOT')
	```

3. Change StarterPlugin as following:

	```java
	@Component
	public class StarterPlugin extends BasePlugin {
	
	    private final ApplicationContext appContext;
	
	    public StarterPlugin(PluginContext pluginContext, ApplicationContext appContext) {
	        super(pluginContext);
	        this.appContext = appContext;
	    }
	
	    @Override
	    public void start() {
	        appContext.publishEvent(new PostDeletedEvent(this, "fake-plugin"));
	    }
	
	    @Override
	    public void stop() {
	    }

	    @EventListener(PostDeletedEvent.class)
	    public void onApplicationEvent(PostDeletedEvent event) {
	        System.out.println("Post deleted event received in plugin: " + event.getName());
	    }
	}
	```
4. Add a listener to Halo core
```java
	    @EventListener(PostDeletedEvent.class)
	    public void onApplicationEvent(PostDeletedEvent event) {
	        System.out.println("Post deleted event received in core: " + event.getName());
	    }
```
5. Build plugin and install plugin
6. Enable the plugin and see the result

#### Does this PR introduce a user-facing change?

```release-note
None
```
2024-06-19 16:11:00 +00:00
..
authentication Fix typo of authentication document (#4717) 2023-10-12 10:00:39 +00:00
cache Enable configuration caching with separate names (#4151) 2023-06-29 07:02:11 +00:00
developer-guide Support configuration properties mechanism for plugin in Halo core (#4043) 2023-06-07 09:55:23 +00:00
email-verification feat: support user email verification mechanism (#4878) 2023-11-27 14:20:09 +00:00
extension-points Provide extension points for authentication-related web filters (#5386) 2024-02-23 09:04:40 +00:00
full-text-search Implement full-text search of posts with Lucene default (#2675) 2022-11-11 16:12:13 +00:00
index feat: add index mechanism for extension (#5121) 2024-01-19 06:36:09 +00:00
notification feat: subscription support for expression-based subscribing (#5705) 2024-04-26 10:26:41 +00:00
plugin Add support for publishing events among plugins (#6081) 2024-06-19 16:11:00 +00:00
backup-and-restore.md Support backup and restore (#4206) 2023-07-24 08:26:16 +00:00