From dd8282024232eb849693e68320e0f0b6bb02bab5 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 8 Feb 2018 11:06:27 +1300 Subject: [PATCH] NEW Allow GridFieldConfig::addComponents to accept an array (#7844) --- src/Forms/GridField/GridFieldConfig.php | 4 ++-- tests/php/Forms/GridField/GridFieldConfigTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Forms/GridField/GridFieldConfig.php b/src/Forms/GridField/GridFieldConfig.php index f74c530ab..72480c649 100644 --- a/src/Forms/GridField/GridFieldConfig.php +++ b/src/Forms/GridField/GridFieldConfig.php @@ -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); } diff --git a/tests/php/Forms/GridField/GridFieldConfigTest.php b/tests/php/Forms/GridField/GridFieldConfigTest.php index d9208bc26..8ea1d81fb 100644 --- a/tests/php/Forms/GridField/GridFieldConfigTest.php +++ b/tests/php/Forms/GridField/GridFieldConfigTest.php @@ -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()