Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony: cascade_validation option is deprecated

Tags:

php

symfony

I am trying to upgrade my project from symfony2 to symfony3. I want to get rid of this deprecation warning

The "cascade_validation" option is deprecated since version 2.8 and will be removed in 3.0. Use "constraints" with a Valid constraint instead."

Below is my code

->add('student_name', 'collection', array(
                'entry_type' => TextType::class,
                'allow_add' => true,
                'cascade_validation' => true,
                'options' => array(
                    'required' => false
                )
            ))

Can I just remove this line 'cascade_validation' => true without causing any trouble? Or what would be the equivalent code in symfony3?

like image 982
asdfkjasdfjk Avatar asked Jun 14 '16 16:06

asdfkjasdfjk


2 Answers

Just replace

'cascade_validation' => true, 

with 

'constraints' => new \Symfony\Component\Validator\Constraints\Valid(),
like image 154
OldaS Avatar answered Nov 15 '22 13:11

OldaS


In Symfony3 you have to use @Assert\Valid constraint in your parent entity. You can remove the line 'cascade_validation' => true in your FormType class.

class Author
{
    /**
     * @Assert\Valid
     */
    protected $address;
}

http://symfony.com/doc/current/reference/constraints/Valid.html

This Symfony commit contains the change and full example how to upgrade.

like image 21
Jibato Avatar answered Nov 15 '22 15:11

Jibato