FEATURE SSF-25 : enable to remove component from a GridFieldConfig.

This commit is contained in:
Normann Lou 2012-03-08 20:00:22 +13:00
parent d24c2ef1ed
commit d35d7507ff
2 changed files with 52 additions and 0 deletions

View File

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

View File

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