silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
722 stars 821 forks source link

Allow moving of fields between tabs #8850

Open chillu opened 5 years ago

chillu commented 5 years ago

It's next to impossible to figure out the incantations for moving a field between tabs, particularly if the fields name clashes with the tab name - which is always the case on scaffolded has_many and many_many relationships. This makes it a very common use case.

We should have a simple API such as FieldList->moveField($fromTabPath, $toTabPath, $fieldName). We could also make this an API on TabSet as well, although I'd rather do that as part of a wider cleanup of FieldList where we remove all tab methods from it. The FieldList API is a big fat mess, and there's going to be a temptation to refactor the whole damn thing. But

sminnee commented 5 years ago

I'm pretty sure that this works:

$fields->addFieldToTab('Root.Content', $fields->dataFieldByName('Panels'));

You could have a shortcut:

$fields->moveDataFieldToTab('Panels', 'Root.Content');

It doesn't work for non-datafields. Referencing non-datafields is a bit ugly, but we could standardise the use of dot-syntax to reference those, e.g.

$fields->moveFieldToTab('Root.Panels.Panels', 'Root.Content');

One issue that this doesn't resolve is auto-deletion of tabs. It might be that remove-from-tab and move-to-tab methods have a boolean flag to autodelete an empty container?

It's worth noting that although these methods talk about "tabs" it's really referencing "nested composite fields". I would probably stick with the naming, though, because:

chillu commented 5 years ago

Yeah addFieldToTab() works. It didn't in my case because the tab title (Content) was different from the name (Main), which got me confused. I still think that we need a "move" API, the "add an existing field" logic is a bit counter intuitive IMHO