Skip to content

Commit

Permalink
Merge pull request #185 from creative-commoners/pulls/1/fix-behat
Browse files Browse the repository at this point in the history
FIX Remove any extra added tabs from SingleTabPage
  • Loading branch information
GuySartorelli authored Jun 13, 2024
2 parents 58c8438 + 5bbeb77 commit 4e241f5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions code/multitab-validation/SingleTabPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Page;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\Tab;

if (!class_exists(Page::class)) {
return;
Expand All @@ -22,4 +23,22 @@ public function getCMSValidator()
'Content'
]);
}

public function getCMSFields()
{
$fields = parent::getCMSFields();
// Page may will extend CWP BasePage if running in a kitchen-sink context,
// so removing any extra tabs added - this class is for a "single tab" test
$tabFieldNames = [];
foreach ($fields->flattenFields() as $field) {
$fieldName = $field->getName();
if (is_a($field, Tab::class) && $fieldName !== 'Main') {
$tabFieldNames[] = $fieldName;
}
}
foreach ($tabFieldNames as $tabFieldName) {
$fields->removeByName($tabFieldName);
}
return $fields;
}
}

0 comments on commit 4e241f5

Please sign in to comment.