<?php
namespace PaperKite\Common\EventSubscriber\EasyAdmin;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityBuiltEvent;
use Lightbulb\Symfony\Service\EntityTranslationService;
use Lightbulb\Symfony\Translatable\TranslatableInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TranslationSubscriber implements EventSubscriberInterface
{
public function __construct(
private EntityTranslationService $entityTranslationService,
) {
}
public static function getSubscribedEvents(): array
{
return [
AfterEntityBuiltEvent::class => 'onAfterEntityBuiltEvent',
];
}
public function onAfterEntityBuiltEvent(AfterEntityBuiltEvent $event)
{
$entityInstance = $event->getEntity()->getInstance();
if ($entityInstance && is_subclass_of($entityInstance, TranslatableInterface::class)) {
$this->entityTranslationService->createDefaultTranslation($entityInstance);
}
}
}