<?php
namespace App\EventSubscriber;
use App\Handler\LanguageHandler;
use App\Event\LanguagePreRemoveEvent;
use App\Event\LanguagePostRemoveEvent;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class LanguageSubscriber implements EventSubscriberInterface
{
public function __construct(
private LanguageHandler $handler,
private EntityManagerInterface $_em,
private TagAwareCacheInterface $esComCache
) {}
public static function getSubscribedEvents(): array
{
return [
LanguagePreRemoveEvent::NAME => 'onPreRemove',
LanguagePostRemoveEvent::NAME => 'onPostRemove'
];
}
public function onPreRemove(LanguagePreRemoveEvent $event)
{
$object = $event->getObject();
$this->handler->deleteAllTranslations($object);
}
public function onPostRemove(LanguagePostRemoveEvent $event)
{
$this->esComCache->invalidateTags(['ES_CONTAINER', 'ES_MY_CONTAINER', 'ES_CLIENT_CID']);
}
}