Permalink
Browse files

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

  • Loading branch information...
1 parent d24c2ef commit d35d7507ff94b48c5c91abb4690147159c158a64 @normann normann committed Mar 8, 2012
Showing with 52 additions and 0 deletions.
  1. +21 −0 forms/gridfield/GridFieldConfig.php
  2. +31 −0 tests/forms/gridfield/GridFieldConfigTest.php
@@ -53,6 +53,27 @@ public function addComponents() {
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 @@ public function testAddComponents() {
);
}
+ 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 {

0 comments on commit d35d750

Please sign in to comment.