mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Update CompositeField::__construct to call setChildren #8460
This commit is contained in:
parent
98afbfe9b4
commit
250d925810
@ -53,16 +53,15 @@ class CompositeField extends FormField
|
||||
|
||||
public function __construct($children = null)
|
||||
{
|
||||
if ($children instanceof FieldList) {
|
||||
$this->children = $children;
|
||||
} elseif (is_array($children)) {
|
||||
$this->children = new FieldList($children);
|
||||
} else {
|
||||
//filter out null/empty items
|
||||
// Normalise $children to a FieldList
|
||||
if (!$children instanceof FieldList) {
|
||||
if (!is_array($children)) {
|
||||
// Fields are provided as a list of arguments
|
||||
$children = array_filter(func_get_args());
|
||||
$this->children = new FieldList($children);
|
||||
}
|
||||
$this->children->setContainerField($this);
|
||||
$children = new FieldList($children);
|
||||
}
|
||||
$this->setChildren($children);
|
||||
|
||||
parent::__construct(null, false);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace SilverStripe\Forms\Tests;
|
||||
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\Forms\CompositeField;
|
||||
use SilverStripe\Forms\DropdownField;
|
||||
@ -107,4 +108,20 @@ class CompositeFieldTest extends SapphireTest
|
||||
"Validates when children are valid"
|
||||
);
|
||||
}
|
||||
|
||||
public function testChildren()
|
||||
{
|
||||
$field = CompositeField::create();
|
||||
|
||||
$this->assertInstanceOf(FieldList::class, $field->getChildren());
|
||||
$this->assertEquals($field, $field->getChildren()->getContainerField());
|
||||
|
||||
$expectedChildren = FieldList::create(
|
||||
$fieldOne = DropdownField::create('A', '', [ 'value' => 'value' ]),
|
||||
$fieldTwo = TextField::create('B')
|
||||
);
|
||||
$field->setChildren($expectedChildren);
|
||||
$this->assertEquals($expectedChildren, $field->getChildren());
|
||||
$this->assertEquals($field, $expectedChildren->getContainerField());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user