<?php
namespace Plugin\FwEasyHoliday42;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class Event implements EventSubscriberInterface
{
private $urlGenerator;
public function __construct(UrlGeneratorInterface $urlGenerator)
{
$this->urlGenerator = $urlGenerator;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::RESPONSE => 'onKernelResponse',
];
}
public function onKernelResponse(ResponseEvent $event)
{
$request = $event->getRequest();
if ($request->attributes->get('_route') === 'admin_setting_shop_calendar') {
$url = $this->urlGenerator->generate('fw_easy_holiday_admin_edit');
$event->setResponse(new RedirectResponse($url));
}
}
}