Symfony2 Sonata Admin sonata_type_collection inline editing hidden field
Posted by valqk on
Here I've found the answer to my simple question: How to inline edit a dependend one to many field without showing the parent as select box.
http://www.obverse.com/2013/05/working-with-the-sonata-admin-bundle-and-sonata_type_collection/
Here is a brief answer: Use prePersist / preUpdate methods in ParentAdmin.php class.
// in the ParentAdmin class
Yes indeed, the sonata admin class allows for prePersist and preUpdate calls that allows us to set the promotion for the rule before persisting. Of course don’t forget to declare your admin classes as services in your configs. Other than that, I hope that this helps somebody out there.
http://www.obverse.com/2013/05/working-with-the-sonata-admin-bundle-and-sonata_type_collection/
Here is a brief answer: Use prePersist / preUpdate methods in ParentAdmin.php class.
// in the ParentAdmin class
public function prePersist($promotion)
{
foreach ($promotion->getRules() as $rule) {
$rule->setPromotion($promotion);
}
}
public function preUpdate($promotion)
{
foreach ($promotion->getRules() as $rule) {
$rule->setPromotion($promotion);
}
$promotion->setRules($promotion->getRules());
}
Yes indeed, the sonata admin class allows for prePersist and preUpdate calls that allows us to set the promotion for the rule before persisting. Of course don’t forget to declare your admin classes as services in your configs. Other than that, I hope that this helps somebody out there.
Trackbacks
Trackback specific URI for this entryThis link is not meant to be clicked. It contains the trackback URI for this entry. You can use this URI to send ping- & trackbacks from your own blog to this entry. To copy the link, right click and select "Copy Shortcut" in Internet Explorer or "Copy Link Location" in Mozilla.
No Trackbacks
Comments
Display comments as Linear | ThreadedNo comments