src/EventSubscriber/Core/EasyAdminSubscriber.php line 36

Open in your IDE?
  1. <?php
  2. /*
  3.  * @since 1.0.0
  4.  * @copyright Copyright (C) 2020 ArtMedia. All rights reserved.
  5.  * @website http://artmedia.biz.pl
  6.  * @author Arkadiusz Tobiasz
  7.  * @email kontakt@artmedia.biz.pl
  8.  */
  9. namespace App\EventSubscriber\Core;
  10. use App\Entity\Core\Language;
  11. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Bundle\FrameworkBundle\Console\Application;
  14. use Symfony\Component\Console\Input\ArrayInput;
  15. use Symfony\Component\Console\Output\NullOutput;
  16. use Symfony\Component\HttpKernel\KernelInterface;
  17. class EasyAdminSubscriber implements EventSubscriberInterface
  18. {
  19.     private $kernel;
  20.     public function __construct(KernelInterface $kernel)
  21.     {
  22.         $this->kernel $kernel;
  23.     }
  24.     public static function getSubscribedEvents()
  25.     {
  26.         return [
  27.             AfterEntityPersistedEvent::class => ['generateTranslations'],
  28.         ];
  29.     }
  30.     public function generateTranslations(AfterEntityPersistedEvent $event)
  31.     {
  32.         $entity $event->getEntityInstance();
  33.         if (!($entity instanceof Language)) {
  34.             return;
  35.         }
  36.         $application = new Application($this->kernel);
  37.         $application->setAutoExit(false);
  38.         $input = new ArrayInput([
  39.             'command' => 'translation:update',
  40.             'locale' => $entity->getIsoCode(),
  41.             '--force' => true,
  42.         ]);
  43.         $output = new NullOutput();
  44.         $application->run($input$output);
  45.     }
  46. }