NEW Allow GridFieldConfig::addComponents to accept an array (#7844)

This commit is contained in:
Robbie Averill 2018-02-08 11:06:27 +13:00 committed by Damian Mooyman
parent e0e8ca0ee6
commit dd82820242
2 changed files with 15 additions and 2 deletions

View File

@ -68,12 +68,12 @@ class GridFieldConfig
}
/**
* @param GridFieldComponent $component,... One or more components
* @param GridFieldComponent|GridFieldComponent[] $component,... One or more components, or an array of components
* @return $this
*/
public function addComponents($component = null)
{
$components = func_get_args();
$components = is_array($component) ? $component : func_get_args();
foreach ($components as $component) {
$this->addComponent($component);
}

View File

@ -92,6 +92,19 @@ class GridFieldConfigTest extends SapphireTest
);
}
public function testAddComponentsByArray()
{
$config = GridFieldConfig::create()
->addComponents([
$c1 = new MyComponent(),
]);
$this->assertEquals(
$c1,
$config->getComponentByType(MyComponent::class)
);
}
public function testRemoveComponents()
{
$config = GridFieldConfig::create()