src/Juki/Bundle/AppBundle/EventListener/CategorySubscriber.php line 40

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Juki\Bundle\AppBundle\EventListener;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Hitso\Bundle\FormBundle\Event\FormEvent;
  6. use Hitso\Bundle\FormBundle\Form\Type\ImageType;
  7. use Juki\Bundle\AppBundle\Entity\Dictionary\Shop;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Validator\Constraints\Callback;
  12. use Symfony\Component\Validator\Constraints\Count;
  13. use Symfony\Component\Validator\Constraints\Length;
  14. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  15. /**
  16.  * Class CategorySubscriber
  17.  *
  18.  * @package Juki\Bundle\AppBundle\EventListener
  19.  */
  20. final class CategorySubscriber implements EventSubscriberInterface
  21. {
  22.     protected $entityManager;
  23.     public function __construct(EntityManagerInterface $entityManager)
  24.     {
  25.         $this->entityManager $entityManager;
  26.     }
  27.     public static function getSubscribedEvents()
  28.     {
  29.         return [
  30.             'category_type.form_init' => 'onCategoryFormInit',
  31.         ];
  32.     }
  33.     public function onCategoryFormInit(FormEvent $event)
  34.     {
  35.         $builder $event->getBuilder();
  36.         $builder->add(
  37.             'shops',
  38.             ChoiceType::class,
  39.             [
  40.                 'label'              => 'Sklep',
  41.                 'required'           => true,
  42.                 'translation_domain' => 'admin',
  43.                 'multiple'           => false,
  44.                 'expanded'           => false,
  45.                 'choices'            => $this->entityManager->getRepository(Shop::class)->getParentChoices(),
  46.                 'position'           => ['before' => 'name'],
  47. //                'constraints'        => [
  48. //                    new Count([
  49. //                        'min'        => 1,
  50. //                        'minMessage' => 'Musisz wybrać przynajmniej 1 sklep',
  51. //                    ]),
  52. //                ],
  53.             ]
  54.         );
  55.         $builder->add(
  56.             'shortName',
  57.             TextType::class,
  58.             [
  59.                 'label'       => 'Nazwa skrócona',
  60.                 'required'    => false,
  61.                 'empty_data'  => '',
  62.                 'position'    => ['after' => 'name'],
  63.                 'constraints' => [new Length(['max' => 255])],
  64.             ]
  65.         );
  66.         $builder->add(
  67.             'navigationIcon',
  68.             ImageType::class,
  69.             [
  70.                 'label'       => 'Ikona nawigacji (SVG)',
  71.                 'config_name' => 'icon_attachment',
  72.                 'required'    => false,
  73.                 'position'    => ['after' => 'photo'],
  74.             ]
  75.         );
  76.     }
  77. }