How to create subgroups in the sonata administrator form

In Sonata, AdminBundle\Mapper\BaseGroupedMapper.php

I saw example code:

    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 (name, etc.), and then tabs below it to display the entity relations tab (onetomany ...) by tab to keep it clean. Unfortunately I am getting 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 were they two separate examples? I would like, if it were possible, not to have clean tabs and therefore not be able to see part of my form all the time.

+3


source to share


1 answer


If you want to use tabs, your entire element must be between tabs.

In your example, you are missing a tab between the first group1, you have to 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 the use ->with('', array('tab' => true)

I used ->tab('')

, it makes more sense.

Also compensated not supported: fooobar.com/questions/2240359 / ...

Documentation: https://sonata-project.org/bundles/admin/master/doc/reference/action_create_edit.html#formgroup-options

+3


source







All Articles