<?php
/*
* @since 1.0.0
* @copyright Copyright (C) 2020 ArtMedia. All rights reserved.
* @website http://artmedia.biz.pl
* @author Arkadiusz Tobiasz
* @email kontakt@artmedia.biz.pl
*/
namespace App\EventSubscriber\Core;
use App\Entity\Core\Language;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\HttpKernel\KernelInterface;
class EasyAdminSubscriber implements EventSubscriberInterface
{
private $kernel;
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
}
public static function getSubscribedEvents()
{
return [
AfterEntityPersistedEvent::class => ['generateTranslations'],
];
}
public function generateTranslations(AfterEntityPersistedEvent $event)
{
$entity = $event->getEntityInstance();
if (!($entity instanceof Language)) {
return;
}
$application = new Application($this->kernel);
$application->setAutoExit(false);
$input = new ArrayInput([
'command' => 'translation:update',
'locale' => $entity->getIsoCode(),
'--force' => true,
]);
$output = new NullOutput();
$application->run($input, $output);
}
}