I am using sonata admin Bundle and other Bundle from Sonata.
I am trying to display some messages. It's working good but I don't want to display all the field when I use the type SONATA_TYPE_COLLECTION.
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('messages', 'sonata_type_collection', array(
'label' => 'Liste des messages',
'required' => false,
'type_options' => array(
// Prevents the "Delete" option from being displayed
'delete' => true,
// 'idPackage' => false,
// 'delete_options' => array(
// // You may otherwise choose to put the field but hide it
// 'type' => 'hidden',
// // In that case, you need to fill in the options as well
// 'type_options' => array(
// 'mapped' => false,
// 'required' => false,
// )
// )
)
), array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
))
And a photo to show my result actually :
I would like to display only :
- delete
- id
- id_user
- créer le
- message but whithout the WYSIWYG
Has someone had the same issue. Thank you for your advices.
What I've done to solve this problem is passing a link-parameter to the add button:
$formMapper->add('messages', 'sonata_type_collection',
array('label' => 'whatever'),
array(
'edit' => 'inline',
'inline' => 'table',
'link_parameters' => array('owner-id' => $this->getSubject()->getId()))
);
So, from the child admin, you can retrieve these arguments from the request and create the admin as you want to for each case:
if ($ownerId = $this->getRequest()->query->get('owner-id')) {
//create your admin differently
}
If what you want to change it's the list of fields already added (not the new ones), you can use:
$parent = $this->getParentFieldDescription();
if ($parent && ( ($entity = $parent->getAdmin()->getSubject()) instanceof MyInterface ) ) {
//do sth here
}