mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Allow to batch-add components via GridFieldConfig->addComponents()
This commit is contained in:
parent
39dc5ae301
commit
9df1487d8f
@ -26,11 +26,23 @@ 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
|
||||
*/
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user