mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
FEATURE SSF-25 : enable to remove component from a GridFieldConfig.
This commit is contained in:
parent
d24c2ef1ed
commit
d35d7507ff
@ -53,6 +53,27 @@ class GridFieldConfig {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GridFieldComponent $component
|
||||
* @return GridFieldConfig $this
|
||||
*/
|
||||
public function removeComponent(GridFieldComponent $component) {
|
||||
$this->getComponents()->remove($component);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String Class name or interface
|
||||
* @return GridFieldConfig $this
|
||||
*/
|
||||
public function removeComponentsByType($type) {
|
||||
$components = $this->getComponentsByType($type);
|
||||
foreach($components as $component) {
|
||||
$this->removeComponent($component);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayList Of GridFieldComponent
|
||||
*/
|
||||
|
@ -82,6 +82,37 @@ class GridFieldConfigTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testRemoveComponents() {
|
||||
$config = GridFieldConfig::create()
|
||||
->addComponent($c1 = new GridFieldConfigTest_MyComponent())
|
||||
->addComponent($c2 = new GridFieldConfigTest_MyComponent())
|
||||
->addComponent($c3 = new GridFieldConfigTest_MyOtherComponent())
|
||||
->addComponent($c4 = new GridFieldConfigTest_MyOtherComponent());
|
||||
|
||||
$this->assertEquals(
|
||||
4,
|
||||
$config->getComponents()->count()
|
||||
);
|
||||
|
||||
$config->removeComponent($c1);
|
||||
$this->assertEquals(
|
||||
3,
|
||||
$config->getComponents()->count()
|
||||
);
|
||||
|
||||
$config->removeComponentsByType("GridFieldConfigTest_MyComponent");
|
||||
$this->assertEquals(
|
||||
2,
|
||||
$config->getComponents()->count()
|
||||
);
|
||||
|
||||
$config->removeComponentsByType("GridFieldConfigTest_MyOtherComponent");
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$config->getComponents()->count()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class GridFieldConfigTest_MyComponent implements GridField_URLHandler, TestOnly {
|
||||
|
Loading…
x
Reference in New Issue
Block a user