ENHANCEMENT Allow to batch-add components via GridFieldConfig->addComponents()

This commit is contained in:
Ingo Schommer 2012-02-21 22:06:41 +01:00
parent 39dc5ae301
commit 9df1487d8f
2 changed files with 29 additions and 0 deletions

View File

@ -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

View File

@ -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')
);
}
}