How to specify a target entity type with sonata_type_collection

393 views Asked by At

I am using Sonata Page Bundle to build a set of page with information about items -- one item per page. On each page, I want to include multiple synonyms for the item. I have created a Synonym entity with two fields.

I now want to use an add() method within my configureFormFields definition to add a reference to my new Synonym entity. The following code yields an error saying that The current field 'Synonym' is not linked to an admin. Please create one for the target entity : '':

            ->add('Synonym', 'sonata_type_collection', array(
                'label' => "Synonyms",
                'cascade_validation' => true,
                'required' => false
            ), array(
                'edit' => 'inline',
                'inline' => 'table'
            ))

... and I have tried modifying the code so it looks like:

                'cascade_validation' => true,
                'required' => false,
                'target_entity' => 'AppBundle\Entity\Synonym'
            ), array(

... which results in the same error.

How do I tell my admin class that this is a reference to a set of Synonym objects that I want to edit inline?

Edit:

I have also tried

'targetEntity' => 'AppBundle\Entity\Synonym'

... with no luck. The application is still seemingly having trouble figuring out what the entity I'm targeting is.

1

There are 1 answers

0
Mayor of the Plattenbaus On

An at least partial answer was found in adding an "admin_code" definition to my array, as described at

https://symfony.com/doc/master/bundles/SonataAdminBundle/reference/form_types.html

I still get an error, but it is now at least a different error.