src/Form/EventListener/Franchise/Parameter/AddLocaleFieldSubscriber.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Franchise\Parameter;
  4. use App\Entity\Admin\Locale;
  5. use App\Entity\Franchise\Franchise;
  6. use App\Form\FormHelper;
  7. use App\Repository\Admin\LocaleRepository;
  8. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\Form\FormEvent;
  11. use Symfony\Component\Form\FormEvents;
  12. class AddLocaleFieldSubscriber extends FormHelper implements EventSubscriberInterface
  13. {
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  17.     }
  18.     public function preSetData(FormEvent $event): void
  19.     {
  20.         /** @var Franchise $franchise */
  21.         $franchise $event->getData()->getFranchise();
  22.         $queryBuilder = function (LocaleRepository $repository) use ($franchise) {
  23.             return $repository->getLocalesByFranchiseQB($franchise);
  24.         };
  25.         $event->getForm()->add('locale'EntityType::class, $this->getEntityParameters(
  26.             Locale::class,
  27.             'app.global.fields.locale.default_label',
  28.             null,
  29.             true,
  30.             ['query_builder' => $queryBuilder]
  31.         ));
  32.     }
  33. }