src/Juki/Bundle/AppBundle/EventListener/TagSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Juki\Bundle\AppBundle\EventListener;
  4. use Hitso\Bundle\FormBundle\Event\FormEvent;
  5. use Hitso\Bundle\TaggingBundle\Entity\TagType;
  6. use Juki\Bundle\AppBundle\Entity\TagCategory;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\Validator\Constraints\NotBlank;
  10. /**
  11.  * Class TagSubscriber
  12.  *
  13.  * @package Juki\Bundle\AppBundle\EventListener
  14.  */
  15. final class TagSubscriber implements EventSubscriberInterface
  16. {
  17.     public static function getSubscribedEvents()
  18.     {
  19.         return [
  20.             'tag_form_type.form_init' => 'onTagFormInit',
  21.         ];
  22.     }
  23.     public function onTagFormInit(FormEvent $event)
  24.     {
  25.         $builder $event->getBuilder();
  26.         $builder->remove('type');
  27.         $builder->add(
  28.             'type',
  29.             EntityType::class,
  30.             [
  31.                 'label'        => 'Typ',
  32.                 'class'        => TagType::class,
  33.                 'choice_label' => 'name',
  34.                 'required'     => true,
  35.                 'constraints'  => [
  36.                     new NotBlank(),
  37.                 ],
  38.                 'position'     => ['after' => 'description'],
  39.             ]
  40.         );
  41.         $builder->add(
  42.             'category',
  43.             EntityType::class,
  44.             [
  45.                 'label'              => 'Kategoria',
  46.                 'required'           => true,
  47.                 'translation_domain' => 'admin',
  48.                 'multiple'           => false,
  49.                 'expanded'           => false,
  50.                 'choice_label'       => 'name',
  51.                 'class'              => TagCategory::class,
  52.                 'position'           => ['after' => 'type'],
  53.             ]
  54.         );
  55.     }
  56. }