Last active
August 13, 2019 22:45
-
-
Save stecman/6e91615824da0b4db145 to your computer and use it in GitHub Desktop.
Remove empty tabs in the SilverStripe CMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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.