use App\Form\EventSubscriber\MyCustomSubscriber; $form = $this->createFormBuilder($entity) ->addEventSubscriber(new MyCustomSubscriber()) ->getForm();
use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Validator\Validation; use Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser; use Symfony\Component\Form\FormFactoryBuilder; $validator = Validation::createValidator(); $formTypeGuesser = new ValidatorTypeGuesser($validator); $formFactoryBuilder = new FormFactoryBuilder(); $formFactoryBuilder->addTypeGuesser($formTypeGuesser); $formFactory = $formFactoryBuilder->getFormFactory(); $form = $formFactory->createBuilder(FormType::class) ->add('name') ->add('email') ->getForm();In the first example, the "MyCustomSubscriber" class is a custom event subscriber that you have implemented. You can attach any event subscriber to the form builder using this method. In the second example, a built-in validation event subscriber is attached to the form builder. This requires some additional setup code to create the validator and type guesser objects, but once you have these set up, you can attach the event subscriber to any form builder instance that you create. The package library is Symfony\Component\Form.