src/EventSubscriber/LanguageSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Handler\LanguageHandler;
  4. use App\Event\LanguagePreRemoveEvent;
  5. use App\Event\LanguagePostRemoveEvent;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Contracts\Cache\TagAwareCacheInterface;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class LanguageSubscriber implements EventSubscriberInterface
  10. {
  11.     public function __construct(
  12.         private LanguageHandler $handler,
  13.         private EntityManagerInterface $_em,
  14.         private TagAwareCacheInterface $esComCache
  15.     ) {}
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             LanguagePreRemoveEvent::NAME => 'onPreRemove',
  20.             LanguagePostRemoveEvent::NAME => 'onPostRemove'
  21.         ];
  22.     }
  23.     public function onPreRemove(LanguagePreRemoveEvent $event)
  24.     {
  25.         $object $event->getObject();
  26.         $this->handler->deleteAllTranslations($object);
  27.     }
  28.     public function onPostRemove(LanguagePostRemoveEvent $event)
  29.     {
  30.         $this->esComCache->invalidateTags(['ES_CONTAINER''ES_MY_CONTAINER''ES_CLIENT_CID']);
  31.     }
  32. }