Tab order

Silverstripe Version: 4.3

Question:

I have a tab I would like to place directly after the Content tab within the Admin section of the site. I can achieve this with the following code;

$fields->insertAfter(new Tab('Root.BackgroundInformation', 'Background information'), 'Main');

However, I would like to add some tabs within the ‘Background information’ tab. I have tried using the following code;

$fields->addFieldToTab('Root.BackgroundInformation.General', TextField::create('Students','Year level')
    ->setDescription('Year level/s best suited to (e.g. Year 5 or Years 5 to 12)'
));

But this breaks the admin section when I refresh the page.

The only way I seem to be able to have tabs within a tab is with;

$fields->findOrMakeTab('Root.BackgroundInformation.General', 'General');
$fields->findOrMakeTab('Root.BackgroundInformation.ClassroomActivity', 'Classroom activity');
$fields->findOrMakeTab('Root.BackgroundInformation.UnitOfWork', 'Unit of work');
$fields->findOrMakeTab('Root.BackgroundInformation', 'Background information');

$fields->addFieldToTab('Root.BackgroundInformation.General', TextField::create('Students','Year level')
    ->setDescription('Year level/s best suited to (e.g. Year 5 or Years 5 to 12)'
));

...

Problem is, this does not allow me to place the tab after the ‘Content’ tab.

Can someone please help with a solution to this.

Thanks

Maybe try:
$fields->addFieldsToTab(‘main’,[ Field1, Field2, Field3 ]);

Thank you for your response. Although this does allow me to clean up my field placement, I am still unable to place the ‘Background information’ tab directly after the ‘Content’ tab.

Found this old post when needing to change tab not field order.

The answer is tabs are also fields. Just not data fields.

Assuming you have Root.Tab1 and Root.Tab2 filled with fields already:


// Get the tab fields
$tab1 = $fields->fieldByName('Root.Tab1');
$tab2 = $fields->fieldByName('Root.Tab2');

// Remove from Root
$fields->removeFieldsFromTab('Root', ['Tab1', 'Tab2']);

// Add in your order
$fields->addFieldsToTab('Root', [$tab2, $tab1]);