Justoverclock I don't know whether this'll help, but I went and got a response to your query from a code bot.
The response:
Step-by-Step Guide to Listening for Events in Flarum
Set Up Your Flarum Extension:
•First, ensure you have a Flarum extension set up. If you haven't created one yet, you can do so by following these steps:
composer create-project flarum/flarum-ext <your-extension-name>
•Replace <your-extension-name> with your desired extension name.
Register Event Listeners:
•In your extension, you will need to register event listeners. This is typically done in the extend.php file of your extension. Here’s how you can listen for the closing of discussions and liking of posts:
use Flarum\Post\Event\PostWasLiked;
use Flarum\Foundation\AbstractServiceProvider;
class YourExtensionServiceProvider extends AbstractServiceProvider
{
public function boot()
{
$this->app['events']->listen(DiscussionWasClosed::class, function (DiscussionWasClosed $event) {
// Handle the discussion close event
$discussion = $event->discussion;
// Your logic here, e.g., logging or sending notifications
});
$this->app['events']->listen(PostWasLiked::class, function (PostWasLiked $event) {
// Handle the post liked event
$post = $event->post;
// Your logic here, e.g., updating a counter or sending notifications
});
}
}
•In this code snippet, we are listening for two specific events: DiscussionWasClosed and PostWasLiked. When these events are triggered, the corresponding anonymous functions will execute, allowing you to implement your custom logic.
Implement Your Logic:
•Inside the event listeners, you can implement any logic you need. For example, you might want to log the event, send an email notification, or update a database record.
Here’s a simple example of logging:
use Illuminate\Support\Facades\Log;
$this->app['events']->listen(DiscussionWasClosed::class, function (DiscussionWasClosed $event) {
$discussion = $event->discussion;
Log::info('Discussion closed: ' . $discussion->title);
});