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,11 +26,23 @@ class GridFieldConfig {
$this->components = new ArrayList(); $this->components = new ArrayList();
} }
/**
* @param GridFieldComponent $component
*/
public function addComponent(GridFieldComponent $component) { public function addComponent(GridFieldComponent $component) {
$this->getComponents()->push($component); $this->getComponents()->push($component);
return $this; 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 * @return ArrayList Of GridFieldComponent
*/ */

View File

@ -65,6 +65,23 @@ class GridFieldConfigTest extends SapphireTest {
); );
} }
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')
);
}
} }
class GridFieldConfigTest_MyComponent implements GridField_URLHandler, TestOnly { class GridFieldConfigTest_MyComponent implements GridField_URLHandler, TestOnly {