Andy
Andy

Reputation: 727

Sonata admin bundle add new manyToOne entity to current entity

I have an entity that has a manyToOne with a subsequent entity. On the edit page of the parent i have a 2 column layout. On the right i would like to list the current linked entities in the collection and then have an "add new" button to either create a new entity and link it or link an existing one.

i am looking at using a collection, but i cant seem to format it to only show the name of the child.

enter image description here I have a solution where i use the "help" to print the topics but cant generate the add new button. The screenshot above shows a little of what i mean. it's rendering the whole form.

Upvotes: 1

Views: 518

Answers (2)

Jim Panse
Jim Panse

Reputation: 2270

You could also check whats the parent admin in your embedded admin and add only fields if its not the admin which should only contain the topic.name.

if ($this->getRoot()->getClass() != 'Your\Parent\Class\Containing\Topic\Name') {
 $formMapper->add(...); // all fields for 'full' view going here
}

Be aware of fields which are required. If you don't fill them, you'll get an error on save if you don't fill them otherwise.

Upvotes: 0

fbaudet
fbaudet

Reputation: 274

you may test to add a key btn_add to "New" to the third parameter ?

->add('topics', 'sonata_type_collection', array('btn_add' => "New"))

Or be sure to your route /topic/create is available for your child entity ?

Upvotes: 1

Related Questions