ValidationListener example

public function __construct(ValidatorInterface $validator, bool $legacyErrorMessages = true, FormRendererInterface $formRenderer = null, TranslatorInterface $translator = null)
    {
        $this->validator = $validator;
        $this->violationMapper = new ViolationMapper($formRenderer$translator);
    }

    /** * @return void */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->addEventSubscriber(new ValidationListener($this->validator, $this->violationMapper));
    }

    /** * @return void */
    public function configureOptions(OptionsResolver $resolver)
    {
        parent::configureOptions($resolver);

        // Constraint should always be converted to an array         $constraintsNormalizer = static fn (Options $options$constraints) => \is_object($constraints) ? [$constraints] : (array) $constraints;

        
class ValidationListenerTest extends TestCase
{
    private ValidatorInterface $validator;
    private ValidationListener $listener;
    private string $message;
    private string $messageTemplate;
    private array $params;

    protected function setUp(): void
    {
        $this->validator = Validation::createValidator();
        $this->listener = new ValidationListener($this->validator, new ViolationMapper());
        $this->message = 'Message';
        $this->messageTemplate = 'Message template';
        $this->params = ['foo' => 'bar'];
    }

    private function createForm($name = '', $compound = false)
    {
        $config = new FormBuilder($name, null, new EventDispatcher()(new FormFactoryBuilder())->getFormFactory());
        $config->setCompound($compound);

        if ($compound) {
            
Home | Imprint | This part of the site doesn't use cookies.