src/Form/EventSubscriber/MaxFirmware/MaxFirmwareStatusFieldSubscriber.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventSubscriber\MaxFirmware;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  6. use Symfony\Component\Form\FormEvent;
  7. use Symfony\Component\Form\FormEvents;
  8. use Symfony\Component\Validator\Constraints\NotBlank;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. class MaxFirmwareStatusFieldSubscriber implements EventSubscriberInterface
  11. {
  12.     public function __construct(private TranslatorInterface $translator)
  13.     {
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [FormEvents::PRE_SET_DATA => 'onPreSetData'];
  18.     }
  19.     public function onPreSetData(FormEvent $event): void
  20.     {
  21.         $form $event->getForm();
  22.         $form->add('status'ChoiceType::class, [
  23.             'choices' => [
  24.                 'Beta Testing' => 'testing',
  25.                 'Live' => 'live',
  26.                 'Disabled' => 'disabled',
  27.             ],
  28.             'constraints' => [
  29.                 new NotBlank(['message' => $this->translator->trans('customStrings.form.firmware_management.status_required_error')]),
  30.             ],
  31.         ]);
  32.     }
  33. }