<?php
declare(strict_types=1);
namespace App\Form\EventListener\Migrate;
use App\Client\Foxorders_V1\FoxordersClient;
use App\Form\FormHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class AddExternalFranchiseSubscriber extends FormHelper implements EventSubscriberInterface
{
public function __construct(
private TokenStorageInterface $tokenStorage,
private FoxordersClient $foxordersClient
) {
}
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$event->getForm()->add('externalFranchise', ChoiceType::class, $this->getChoiceParameters(
'app.global.user.migration.form.external_franchise',
'app.global.user.migration.form.external_franchise',
false,
[
'choices' => $this->foxordersClient->getFranchises(),
]
));
}
}