src/Juki/Bundle/AppBundle/EventListener/SlideSubscriber.php line 33

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Juki\Bundle\AppBundle\EventListener;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Doctrine\ORM\EntityRepository;
  6. use Hitso\Bundle\FormBundle\Event\FormEvent;
  7. use Juki\Bundle\AppBundle\Entity\Dictionary\Shop;
  8. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Validator\Constraints\Count;
  13. final class SlideSubscriber implements EventSubscriberInterface
  14. {
  15.     protected $entityManager;
  16.     public function __construct(EntityManagerInterface $entityManager)
  17.     {
  18.         $this->entityManager $entityManager;
  19.     }
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             'slide_form_type.form_init' => 'onSlideFormInit',
  24.         ];
  25.     }
  26.     public function onSlideFormInit(FormEvent $event)
  27.     {
  28.         $builder $event->getBuilder();
  29.         $builder->add(
  30.             'mode',
  31.             ChoiceType::class,
  32.             [
  33.                 'label'    => 'Wizualizacja',
  34.                 'choices'  => [
  35.                     'jasna'  => 'light',
  36.                     'ciemna' => 'dark',
  37.                 ],
  38.                 'position' => ['after' => 'target'],
  39.             ]
  40.         );
  41.         $builder->add(
  42.             'ctaTitle',
  43.             TextType::class,
  44.             [
  45.                 'label'    => 'Tytuł CTA',
  46.                 'position' => ['after' => 'url'],
  47.                 'required' => false,
  48.             ]
  49.         );
  50.         $builder->add(
  51.             'ctaSubTitle',
  52.             TextType::class,
  53.             [
  54.                 'label'    => 'Podtytuł CTA',
  55.                 'position' => ['after' => 'ctaTitle'],
  56.                 'required' => false,
  57.             ]
  58.         );
  59.         $builder->add(
  60.             'slideButton',
  61.             TextType::class,
  62.             [
  63.                 'label'    => 'Tekst przewijania',
  64.                 'position' => ['after' => 'ctaSubTitle'],
  65.                 'required' => false,
  66.             ]
  67.         );
  68.         $builder->add(
  69.             'shops',
  70.             ChoiceType::class,
  71.             [
  72.                 'label'              => 'Sklep',
  73.                 'required'           => true,
  74.                 'translation_domain' => 'admin',
  75.                 'multiple'           => false,
  76.                 'expanded'           => false,
  77.                 'choices'            => $this->entityManager->getRepository(Shop::class)->getParentChoices(),
  78.                 'position'           => ['before' => 'target'],
  79.             ]
  80.         );
  81.     }
  82. }