<?php
declare(strict_types=1);
namespace Juki\Bundle\AppBundle\EventListener;
use Hitso\Bundle\FormBundle\Event\FormEvent;
use Hitso\Bundle\TaggingBundle\Entity\TagType;
use Juki\Bundle\AppBundle\Entity\TagCategory;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* Class TagSubscriber
*
* @package Juki\Bundle\AppBundle\EventListener
*/
final class TagSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'tag_form_type.form_init' => 'onTagFormInit',
];
}
public function onTagFormInit(FormEvent $event)
{
$builder = $event->getBuilder();
$builder->remove('type');
$builder->add(
'type',
EntityType::class,
[
'label' => 'Typ',
'class' => TagType::class,
'choice_label' => 'name',
'required' => true,
'constraints' => [
new NotBlank(),
],
'position' => ['after' => 'description'],
]
);
$builder->add(
'category',
EntityType::class,
[
'label' => 'Kategoria',
'required' => true,
'translation_domain' => 'admin',
'multiple' => false,
'expanded' => false,
'choice_label' => 'name',
'class' => TagCategory::class,
'position' => ['after' => 'type'],
]
);
}
}