Symfony2 Sonata Admin sonata_type_collection inline editing hidden field

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


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 entry

This 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 | Threaded

No comments

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA