mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Fix disappearing fields when a field without a name was being pushed onto a FieldSet (eg a CompositeField)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64263 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
f58014490c
commit
68aaa32e86
@ -163,6 +163,10 @@ class FieldSet extends DataObjectSet {
|
|||||||
* be left as-is.
|
* be left as-is.
|
||||||
*/
|
*/
|
||||||
public function removeByName($fieldName, $dataFieldOnly = false) {
|
public function removeByName($fieldName, $dataFieldOnly = false) {
|
||||||
|
if(!$fieldName) {
|
||||||
|
user_error('FieldSet::removeByName() was called with a blank field name.', E_USER_WARNING);
|
||||||
|
}
|
||||||
|
|
||||||
foreach($this->items as $i => $child) {
|
foreach($this->items as $i => $child) {
|
||||||
if(is_object($child) && ($child->Name() == $fieldName || $child->Title() == $fieldName) && (!$dataFieldOnly || $child->hasData())) {
|
if(is_object($child) && ($child->Name() == $fieldName || $child->Title() == $fieldName) && (!$dataFieldOnly || $child->hasData())) {
|
||||||
//if($child->class == 'Tab' && !$dataFieldOnly) Debug::backtrace();
|
//if($child->class == 'Tab' && !$dataFieldOnly) Debug::backtrace();
|
||||||
@ -385,7 +389,7 @@ class FieldSet extends DataObjectSet {
|
|||||||
*/
|
*/
|
||||||
function beforeInsert($item) {
|
function beforeInsert($item) {
|
||||||
if($this->sequentialSet) $this->sequentialSet = null;
|
if($this->sequentialSet) $this->sequentialSet = null;
|
||||||
$this->rootFieldSet()->removeByName($item->Name(), true);
|
if($item->Name()) $this->rootFieldSet()->removeByName($item->Name(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -281,6 +281,14 @@ class FieldSetTest extends SapphireTest {
|
|||||||
|
|
||||||
/* There are now 2 fields in the set */
|
/* There are now 2 fields in the set */
|
||||||
$this->assertEquals(2, $fields->Count());
|
$this->assertEquals(2, $fields->Count());
|
||||||
|
|
||||||
|
// Test that pushing a composite field without a name onto the set works
|
||||||
|
// See ticket #2932
|
||||||
|
$fields->push(new CompositeField(
|
||||||
|
new TextField('Test1'),
|
||||||
|
new TextField('Test2')
|
||||||
|
));
|
||||||
|
$this->assertEquals(3, $fields->Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user