<?php
declare(strict_types=1);
namespace App\Form\EventListener\Global;
use App\Entity\Currency\Currency;
use App\Form\FormHelper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class AddCurrencyFieldSubscriber extends FormHelper implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
/** @var Shop $shop */
$shop = $event->getData();
if (null === $shop || null === $shop->getId()) {
return;
}
$event->getForm()->add('currency', EntityType::class, $this->getEntityParameters(Currency::class, 'app.global.fields.currency.label', self::PLACEHOLDER_CUSTOM, true));
}
}