Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…ponents()
  • Loading branch information...
commit 9df1487d8fadc59dfe9e7aac4d90d13525c8368e 1 parent 39dc5ae
@chillu chillu authored
View
12 forms/gridfield/GridFieldConfig.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
View
17 tests/forms/gridfield/GridFieldConfigTest.php
@@ -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')
+ );
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.