Closed EricSivilog closed 4 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:
add()
invokes addFieldToCurrentGroup
.addFieldToCurrentGroup
calls getCurrentGroupName
.getCurrentGroupName
has side effects, because it automatically creates a new group if there is none open.Of course, this behavior doesn’t go well with the fake indentation-style syntax and also isn’t documented anywhere.
Hello guys. Has anybody solved this issue so far or do we always have to use another ->end()
at ->tab()
end?
Hello. There is a fix to this?
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.
Hello,
The issue is still there.
Thanks
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()
;
Thanks for the explanation, that's very clear. Maybe it shouldn't add the admin label by default if there is a tab.
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 ?
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 :
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 ! :-)