sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Adding tabs without groups in Admin Forms #3524

Closed EricSivilog closed 4 years ago

EricSivilog commented 8 years ago

Hi there !

I am using Sonata Admin to develop the backend of my website, and came accross some strange behaviour yesterday. I am basically trying to have a form with two tabs, but do not need groups in each of these tabs. Hence I used in configureFormFields :

                ->tab('Infos')
                    ->add('name')
              ->end()
                ->tab('Jaquettes')
                ->end()
                ;

When doing so, I get an error that says: You should close previous tab "Infos" with end() before adding new tab "Jaquettes". If I enclose the "->add('name')" within a with/end statement (i.e. a group), everything works as expected. Curiously, if I keep the scheme above but add another "->end()" after the first one, things work fine too.

This is using Admin Bundle version "dev-master 2e68c08". Is that the expected behaviour, i.e. do we have to use groups when using tabs? Thanks a lot ! :-)

debach commented 8 years ago

I came accross the same issue and

->tab('Infos')
    ->add('name')
->end()
->end() // what the heck?
->tab('Jaquettes')
->end();

works as you have said.

Basically, what happens is this:

Of course, this behavior doesn’t go well with the fake indentation-style syntax and also isn’t documented anywhere.

StanislavUngr commented 6 years ago

Hello guys. Has anybody solved this issue so far or do we always have to use another ->end() at ->tab() end?

lainosantos commented 6 years ago

Hello. There is a fix to this?

stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

arirangz commented 4 years ago

Hello,

The issue is still there.

Thanks

wbloszyk commented 4 years ago

It is not bug but this things can be improve. add() methods calls addFieldToCurrentGroup($fieldName) which call protected function getCurrentGroupName():

protected function getCurrentGroupName()
    {
        if (!$this->currentGroup) {
            $this->with($this->admin->getLabel(), ['auto_created' => true]);
        }

        return $this->currentGroup;
    }

It's mean:

->tab('Infos')
    ->add('name') //it is equal to ->with($this->admin->getLabel(), ['auto_created' => true])->add('name')
->end() // this end is for with() called by add('name')
->end() // this end is for tab() 
->tab('Jaquettes')
->end()
;
arirangz commented 4 years ago

Thanks for the explanation, that's very clear. Maybe it shouldn't add the admin label by default if there is a tab.

VincentLanglet commented 4 years ago

I think that the auto_created should not count when calling the method end().

->tab('Infos')
    ->add('name') //it is equal to ->with($this->admin->getLabel(), ['auto_created' => true])->add('name')
->end() // this end is for with() called by add('name') but since it's auto_created, it close the tab too.
->tab('Jaquettes')
->end()
;

Do you want to make a PR arirangz ?