Symfony 3 unique constraint in form with non mapped field

Viewed 1006

I'm using Symfony 3 and I'm working on a form without a mapped entity, with data_class => null like :

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('firstname', null, ['label' => 'user.edit.label.firstname'])
            ->add('lastname', null, ['label' => 'user.edit.label.lastname'])
            ->add('email', EmailType::class, ['label' => 'common.email', ])
            ->add('state', ChoiceType::class, [
                'label' => 'common.state',
                'choices' => array_flip(CompanyHasUser::getConstants())
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => null,
            'translation_domain' => 'messages'
        ));
    }

So with this, how can I constraint my field 'email' to be unique ? I need to check that in my entity User (attribute=email).

Any ideas ?

1 Answers
Related