In Sonata's AdminBundle\Mapper\BaseGroupedMapper.php
, I saw a code example:
public function with($name, array $options = array())
{
/*
* The current implementation should work with the following workflow:
*
* $formMapper
* ->with('group1')
* ->add('username')
* ->add('password')
* ->end()
* ->with('tab1', array('tab' => true))
* ->with('group1')
* ->add('username')
* ->add('password')
* ->end()
* ->with('group2', array('collapsed' => true))
* ->add('enabled')
* ->add('createdAt')
* ->end()
* ->end();
*
*/
Unfortunately, I get an error if I add a group first and THEN add tabs. I want my form to have a main simple form (firstname, etc...), and then tabs under it to list the entity relation forms (onetomany...) tab by tab to keep it clean. Unfortunately, I get this error:
New tab was added automatically when you have added field or group. You should close current tab before adding new one OR add tabs before adding groups and fields.
Does anyone know how to make this work ? Or this was 2 separated examples? I would like if possible to avoid having pure tabs and therefore not being able to have a part of my form constantly visible.
If you want to use tabs all your element must be between tabs.
In your example you are missing a tab between the first group1, you should do this :
$formMapper
->tab('General')
->with('group1')
->add('username')
->add('password')
->end()
->end()
->tab('Relations')
->with('group1')
->add('username')
->add('password')
->end()
->with('group2')
->add('enabled')
->add('createdAt')
->end()
->end();
Instead of using ->with('', array('tab' => true)
I used ->tab('')
, makes more sense.
Also collapsed is no more supported : https://stackoverflow.com/a/29105992/3726645
Documentation : https://sonata-project.org/bundles/admin/master/doc/reference/action_create_edit.html#formgroup-options