Reputation: 2796
Suppose you have ArticleAdmin
and CommentsAdmin
. It is easy to add one-to-many editing in Sonata:
$formMapper->add('comments', 'sonata_type_collection',
array(
'by_reference' => false,
),
array(
'edit' => 'inline',
'inline' => 'table',
)
);
However, suppose I have more complicated CommentsAdmin
form and it can has two visualizations depending on the kind of comment in it. I would like to display two sonata_type_collection fields in ArticleAdmin
for grouping different types of comments into two different edit tables.
Adding another add('comments', ...)
is of course incorrect, and adding add('comments2', ...)
results in exception.
I will manage separating comments between two fields in admin, but how to create sonata_type_collection
field on a virtual entity field Article::comments2
? How to tell Sonata Admin what kind of collection should it be?
Upvotes: 1
Views: 2509
Reputation: 1819
I'm not sure if this will help you but:
->add('categoryHasMedia', 'sonata_type_collection', array(
'cascade_validation' => true,
'label' => 'Logo\'s'
), array(
'edit' => 'inline',
'inline' => 'table',
'link_parameters' => array('context' => $context),
'admin_code' => 'appstrakt.project.admin.category_has_media',
))
By using admin_code you can tell which admin class you want to use for that sonata_type_collection if I'm not mistaken.
Upvotes: 1