简体   繁体   中英

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.

在此处输入图片说明 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.

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM