ENHANCEMENT #6228 FieldSet::addFieldsToTab() now allows inserting before a field name for consistency with addFieldToTab()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@114817 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2010-12-11 02:31:49 +00:00
parent 1ca5ea6fb4
commit ec661a9886

View File

@ -112,23 +112,25 @@ class FieldSet extends DataObjectSet {
* This function will create any missing tabs.
* @param array $fields An array of {@link FormField} objects.
*/
public function addFieldsToTab($tabName, $fields) {
public function addFieldsToTab($tabName, $fields, $insertBefore = null) {
$this->flushFieldsCache();
// Find the tab
$tab = $this->findOrMakeTab($tabName);
// Add the fields to the end of this set
foreach($fields as $field) {
// Check if a field by the same name exists in this tab
if($tab->fieldByName($field->Name())) {
if($insertBefore) {
$tab->insertBefore($field, $insertBefore);
} elseif($tab->fieldByName($field->Name())) {
// It exists, so we need to replace the old one
$this->replaceField($field->Name(), $field);
} else {
$tab->push($field);
}
}
}
}
/**
* Remove the given field from the given tab in the field.