Skip to content

Instantly share code, notes, and snippets.

@stecman
Last active August 13, 2019 22:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stecman/6e91615824da0b4db145 to your computer and use it in GitHub Desktop.
Save stecman/6e91615824da0b4db145 to your computer and use it in GitHub Desktop.
Remove empty tabs in the SilverStripe CMS
/**
* Recurse through tabs and remove any with no child fields
*
* The way SilverStripe's field scaffolding works can leave empty tabs around after
* fields are moved or removed by the slices module.
*
* @param FieldList $fields
* @return FieldList
*/
protected function removeEmptyTabs(FieldList $fields)
{
foreach ($fields as $field) {
if ($field instanceof TabSet) {
$this->removeEmptyTabs($field->Tabs());
}
if ($field instanceof Tab && $field->Fields()->count() == 0) {
$fields->remove($field);
}
}
return $fields;
}
@lpostiglione
Copy link

That cant be working, method call in line 14 uses 2 parameters, but method signature uses 1 parameter

@stecman
Copy link
Author

stecman commented Jan 2, 2019

@lpostiglione it's legal in PHP to pass more arguments than a function accepts - this code works (at least in SS3), I just hadn't noticed that extra junk argument hanging around. Will fix now, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment