Permalink
Browse files

API Adds getManipulatedList() method to GridField to get the SS_List …

…after applying Manipulators
  • Loading branch information...
simonwelsh committed Sep 6, 2012
1 parent 19bdd4b commit 4ead89a4d0d90cffc0a8891fb8aca2165ab0989d
Showing with 40 additions and 6 deletions.
  1. +16 −6 forms/gridfield/GridField.php
  2. +24 −0 tests/forms/GridFieldTest.php
@@ -192,6 +192,21 @@ public function setList(SS_List $list) {
public function getList() {
return $this->list;
}
+
+ /**
+ * Get the datasource after applying the {@link GridField_DataManipulator}s to it.
+ *
+ * @return SS_List
+ */
+ public function getManipulatedList() {
+ $list = $this->getList();
+ foreach($this->getComponents() as $item) {
+ if($item instanceof GridField_DataManipulator) {
+ $list = $item->getManipulatedData($this, $list);
+ }
+ }
+ return $list;
+ }
/**
* Get the current GridState_Data or the GridState
@@ -227,12 +242,7 @@ public function FieldHolder($properties = array()) {
$columns = $this->getColumns();
// Get data
- $list = $this->getList();
- foreach($this->getComponents() as $item) {
- if($item instanceof GridField_DataManipulator) {
- $list = $item->getManipulatedData($this, $list);
- }
- }
+ $list = $this->getManipulatedList();
// Render headers, footers, etc
$content = array(
@@ -392,6 +392,22 @@ public function testCanViewOnlyOddIDs() {
$this->assertEquals((string)$members[1]->td[0], 'Otto Fischer', 'Second object Name should be Otto Fischer');
$this->assertEquals((string)$members[1]->td[1], 'otto.fischer@example.org', 'Second object Email should be otto.fischer@example.org');
}
+
+ public function testChainedDataManipulators() {
+ $config = new GridFieldConfig();
+ $data = new ArrayList(array(1, 2, 3, 4, 5, 6));
+ $gridField = new GridField('testfield', 'testfield', $data, $config);
+ $endList = $gridField->getManipulatedList();
+ $this->assertEquals($endList->Count(), 6);
+
+ $config->addComponent(new GridFieldTest_Component2);
+ $endList = $gridField->getManipulatedList();
+ $this->assertEquals($endList->Count(), 12);
+
+ $config->addComponent(new GridFieldPaginator(10));
+ $endList = $gridField->getManipulatedList();
+ $this->assertEquals($endList->Count(), 10);
+ }
}
class GridFieldTest_Component implements GridField_ColumnProvider, GridField_ActionProvider, TestOnly{
@@ -430,6 +446,14 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat
}
+class GridFieldTest_Component2 implements GridField_DataManipulator, TestOnly {
+ function getManipulatedData(GridField $gridField, SS_List $dataList) {
+ $dataList = clone $dataList;
+ $dataList->merge(new ArrayList(array(7, 8, 9, 10, 11, 12)));
+ return $dataList;
+ }
+}
+
class GridFieldTest_Team extends DataObject implements TestOnly {
static $db = array(
'Name' => 'Varchar',

0 comments on commit 4ead89a

Please sign in to comment.