php - Sonata admin "sonata_type_collection" tries to remove entity -
i have 2 entities , 2 admin classes(stripepage , stripe) them. form looks good, has fields , button add new subforms. when "add new" button clicked, new subform form admin class rendered, if click second time on button or try save entity error appears:
catchable fatal error: argument 1 passed fred\corebundle\entity\stripepage::removestripe() must instance of fred\corebundle\entity\stripe, null given in c:\users\lubimov\openserver\domains\tappic.dev\src\fred\corebundle\entity\stripepage.php
so symfony tries remove entity instead of adding it.
stripepageadmin class:
class stripepageadmin extends admin { protected function configurelistfields(listmapper $listmapper) { $listmapper ->addidentifier('id', null, array('label' => 'id')) ->add('name', null, array('label' => 'page name')); } protected function configureformfields(formmapper $formmapper) { $formmapper ->add('name', 'text', array('label' => 'page name')) ->add('stripes', 'sonata_type_collection', array('label' => 'stripes', 'required' => false, 'by_reference' => false), array('edit' => 'inline', 'inline' => 'table', 'sortable' => 'pos') ) ->end(); } }
stripeadmin class:
class stripeadmin extends admin { protected function configurelistfields(listmapper $listmapper) { $listmapper ->addidentifier('id') ->add('picture', null, array('sortable' => true)) ->add('text', null, array('sortable' => true)) ->add('deep_link', null, array('sortable' => true)); } protected function configureformfields(formmapper $formmapper) { $formmapper ->add('file', 'file', array('label' => 'picture')) ->add('text', null, array('label' => 'text')) ->add('deep_link', 'choice', array( 'choices' => array('test1' => 'test1', 'test' => 'test2'), 'label' => 'deep link', )) ->end(); } }
what problem? stripe form in admin class must configured other way?
well, solution use set 'by_reference' => true
in 'sonata_type_collection' settings.
protected function configureformfields(formmapper $formmapper) { $formmapper ->add('name', 'text', array('label' => 'page name')) ->add('stripes', 'sonata_type_collection', array('label' => 'stripes', 'required' => false, 'by_reference' => true), array('edit' => 'inline', 'inline' => 'table', 'sortable' => 'pos') ) ->end(); }
after need declare setstripes()
method in entity.
public function setstripes(\doctrine\common\collections\arraycollection $stripes) { $this->stripes = $stripes; }
if finds how solve using addstripe()
type of methods, please share here.
Comments
Post a Comment