View more context


I imagine I need the Tab component import?

  1. $fields->insertBefore(new Tab('Root.Hero', 'Hero'), 'Main');
  2.  
  3. $fields->addFieldToTab('Hero', TextField::create('HeroSubtitle','Subtitle'));
(edited)

So that gives me an error saying Fatal error: FieldList::addFieldToTab() Tried to add a tab to object 'SilverStripe\Forms\FieldList' - 'Hero' didn't exist. in /var/www/html/vendor/silverstripe/framework/src/Forms/FieldList.php on line 473

  1. $fields->insertBefore(new Tab('Root.Hero', 'Hero'), 'Main');
  2.  
  3. $fields->addFieldToTab('Root.Hero', TextField::create('HeroSubtitle','Subtitle'));

@Brad.EH I think this is expected - you're adding a tab to "Main", then adding a new tab to Root.Main - which results in two Tabs named Main. What you're looking for on the first line is new TabSet (although ideally you'd use TabSet::create) (edited)

Tabs belong to TabSets TabSets can contain Tabs or more TabSets, Tabs contain Fields.

It's not quite that cut and dry though, since Tabs and TabSets both extend from FormField... it gets very esoteric and relies on developer convention and self management.

$fields->insertBefore(Tab::create('Hero'), 'Main');

  1. $tab = new Tab('Root.Hero', 'Hero');
  2. $tab->push(TextField::create('HeroSubtitle','Subtitle'));