I do not have a lot of Symfony experience, but I'm working on an Symfony 4 application that is using the https://github.com/maximilienGilet/notification-bundle Adding and displaying the notifications is working well, but I'm stuck on handling the events created by the bundle.
A form in a twig template (actually in my base twig template) is calling the bundle post markasseen action which is returning a JSON true message, but now I don't know how to return to the URL (route) from which the post call is done?
This is my routers.yaml which "activates" the bundle controller:
App\EventListener\NotificationListener:
arguments: ['@router']
tags:
- { name: kernel.event_listener, event: mgilet.notification.seen }
As you can see I've tried to pass a router parameter to see if that gives me the possibility to "return", but unfortunately that did not help.
This is the EventListener I've created for handling the bundle event:
<?php
namespace App\EventListener;
use Mgilet\NotificationBundle\Event;
use Mgilet\NotificationBundle\Event\NotificationEvent;
use \Symfony\Bundle\FrameworkBundle\Routing\Router;
use \Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
class NotificationListener
{
private $router;
public function __construct(Router $router) {
$this->router = $router;
}
public function OnMgiletNotificationSeen(Event\NotificationEvent $event): void {
dd($event);
}
}
As I mentioned, the event is caught by the listener, it is returning 'true', but I want to return to the route/controller from where the post action is called.
This is the form in the base template (because I want to show te notifications in all templates) which is calling the notification controller:
<form action="/notifications/1/mark_as_seen/8" method="post">
<button type="submit" class="close">
<span aria-hidden="true">×</span><span class="sr-only">Close</span>
</button>
</form>
Can anyone please help me?