src/Form/EventListener/Migrate/AddExternalFranchiseSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Migrate;
  4. use App\Client\Foxorders_V1\FoxordersClient;
  5. use App\Form\FormHelper;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Form\FormEvent;
  9. use Symfony\Component\Form\FormEvents;
  10. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  11. class AddExternalFranchiseSubscriber extends FormHelper implements EventSubscriberInterface
  12. {
  13.     public function __construct(
  14.         private TokenStorageInterface $tokenStorage,
  15.         private FoxordersClient $foxordersClient
  16.     ) {
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  21.     }
  22.     public function preSetData(FormEvent $event): void
  23.     {
  24.         $event->getForm()->add('externalFranchise'ChoiceType::class, $this->getChoiceParameters(
  25.             'app.global.user.migration.form.external_franchise',
  26.             'app.global.user.migration.form.external_franchise',
  27.             false,
  28.             [
  29.                 'choices' => $this->foxordersClient->getFranchises(),
  30.             ]
  31.         ));
  32.     }
  33. }