Permalink
Browse files

ENHANCEMENT Allow to batch-add components via GridFieldConfig->addCom…

…ponents()
  • Loading branch information...
1 parent 39dc5ae commit 9df1487d8fadc59dfe9e7aac4d90d13525c8368e @chillu chillu committed Feb 21, 2012
Showing with 29 additions and 0 deletions.
  1. +12 −0 forms/gridfield/GridFieldConfig.php
  2. +17 −0 tests/forms/gridfield/GridFieldConfigTest.php
@@ -26,10 +26,22 @@ public function __construct() {
$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
@@ -64,6 +64,23 @@ function testGetComponentByType() {
$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')
+ );
+ }
}

0 comments on commit 9df1487

Please sign in to comment.