Skip to content

Instantly share code, notes, and snippets.

@xavismeh
Last active August 29, 2015 14:16
Show Gist options
  • Save xavismeh/f5ec29684d810ddf8f76 to your computer and use it in GitHub Desktop.
Save xavismeh/f5ec29684d810ddf8f76 to your computer and use it in GitHub Desktop.
Form violation
public function buildForm(FormBuilderInterface $builder, array $options) {
    $builder->add('companyName', 'text', array('required' => false))
    ...
    ;
}


    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'constraints' => array(
                new Callback(array(
                    'methods' => array(
                        array($this, 'checkTypeMandatoryFields'),
                    )
                ))
            )
        ));
    }

In my custom constraint

Won't work

$context->buildViolation('required')
    ->atPath('companyName')
    ->addViolation();

Will do

$context->buildViolation('required')
    ->atPath('[companyName]')
    ->addViolation();

symfony/symfony 2.5.x-dev 80b0970

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment