From 9df1487d8fadc59dfe9e7aac4d90d13525c8368e Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 21 Feb 2012 22:06:41 +0100 Subject: [PATCH] ENHANCEMENT Allow to batch-add components via GridFieldConfig->addComponents() --- forms/gridfield/GridFieldConfig.php | 12 ++++++++++++ tests/forms/gridfield/GridFieldConfigTest.php | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/forms/gridfield/GridFieldConfig.php b/forms/gridfield/GridFieldConfig.php index 30ba84151..b45cde614 100755 --- a/forms/gridfield/GridFieldConfig.php +++ b/forms/gridfield/GridFieldConfig.php @@ -26,10 +26,22 @@ class GridFieldConfig { $this->components = new ArrayList(); } + /** + * @param GridFieldComponent $component + */ public function addComponent(GridFieldComponent $component) { $this->getComponents()->push($component); return $this; } + + /** + * @param GridFieldComponent One or more components + */ + public function addComponents() { + $components = func_get_args(); + foreach($components as $component) $this->addComponent($component); + return $this; + } /** * @return ArrayList Of GridFieldComponent diff --git a/tests/forms/gridfield/GridFieldConfigTest.php b/tests/forms/gridfield/GridFieldConfigTest.php index d1491fbc2..f80447277 100644 --- a/tests/forms/gridfield/GridFieldConfigTest.php +++ b/tests/forms/gridfield/GridFieldConfigTest.php @@ -64,6 +64,23 @@ class GridFieldConfigTest extends SapphireTest { $config->getComponentByType('GridFieldConfigTest_UnknownComponent') ); } + + public function testAddComponents() { + $config = GridFieldConfig::create() + ->addComponents( + $c1 = new GridFieldConfigTest_MyComponent(), + $c2 = new GridFieldConfigTest_MyOtherComponent() + ); + + $this->assertEquals( + $c1, + $config->getComponentByType('GridFieldConfigTest_MyComponent') + ); + $this->assertEquals( + $c2, + $config->getComponentByType('GridFieldConfigTest_MyOtherComponent') + ); + } }