简体   繁体   中英

Sonata Admin type_collection & cascade validation

I am having a problem with implementing the one to many relationship in the sonata admin with the following structure.

->add('adhesions', 'sonata_type_collection', array('by_reference' => false,'required' => false), array(
    'edit' => 'inline',
    'inline' => 'table',
    'sortable'  => 'position',))

With this option : 'edit' => 'inline', i lost default validation defined in AdhesionAdmin like 'required' => true.

So, is there a setting to specify somewhere ? I tried to add 'cascade_validation' => true in settings of the sonata_type_collection but it has not changed.

Another question: can I use popup edit form with the sonata_type_collection ? ('edit' => 'standard')

Any pointers and help is highly appreciated. Thank you

You have to enable cascade_validation. You can do it this way:

  class UserAdmin extends SonataUserAdmin  
  {    
     protected $formOptions = array(
        'cascade_validation' => true        
     );

     /* Rest of your admin class code */


  }

Just use Valid constraint on your entity property instead:

/**
 * @var Object[]
 *
 * @ORM\OneToMany(targetEntity="AppBundle\Entity\Object", mappedBy="myEntity")
 * @Assert\Valid
 */
private $objects;

http://symfony.com/doc/current/reference/forms/types/collection.html#cascade-validation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM