src/Form/EventListener/Global/AddSourceFieldSubscriber.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Global;
  4. use App\Entity\Admin\Source;
  5. use App\Form\FormHelper;
  6. use App\Repository\Admin\SourceRepository;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\Form\FormEvent;
  10. use Symfony\Component\Form\FormEvents;
  11. class AddSourceFieldSubscriber extends FormHelper implements EventSubscriberInterface
  12. {
  13.     public static function getSubscribedEvents(): array
  14.     {
  15.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  16.     }
  17.     public function preSetData(FormEvent $event): void
  18.     {
  19.         $event->getForm()->add('source'EntityType::class, $this->getEntityParameters(
  20.             Source::class,
  21.             'app.global.fields.source',
  22.             self::PLACEHOLDER_CHOICE,
  23.             true,
  24.             ['query_builder' => fn (SourceRepository $repository) => $repository->getEnabledQB()],
  25.         ));
  26.     }
  27. }