Skip to content
This repository
Browse code

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

…after applying Manipulators
  • Loading branch information...
commit 4ead89a4d0d90cffc0a8891fb8aca2165ab0989d 1 parent 19bdd4b
Simon Welsh authored September 06, 2012
22  forms/gridfield/GridField.php
@@ -192,6 +192,21 @@ public function setList(SS_List $list) {
192 192
 	public function getList() {
193 193
 		return $this->list;
194 194
 	}
  195
+
  196
+	/**
  197
+	 * Get the datasource after applying the {@link GridField_DataManipulator}s to it.
  198
+	 *
  199
+	 * @return SS_List
  200
+	 */
  201
+	public function getManipulatedList() {
  202
+		$list = $this->getList();
  203
+		foreach($this->getComponents() as $item) {
  204
+ 			if($item instanceof GridField_DataManipulator) {
  205
+				$list = $item->getManipulatedData($this, $list);
  206
+			}
  207
+		}
  208
+		return $list;
  209
+	}
195 210
 	
196 211
 	/**
197 212
 	 * Get the current GridState_Data or the GridState
@@ -227,12 +242,7 @@ public function FieldHolder($properties = array()) {
227 242
 		$columns = $this->getColumns();
228 243
 
229 244
 		// Get data
230  
-		$list = $this->getList();
231  
-		foreach($this->getComponents() as $item) {
232  
- 			if($item instanceof GridField_DataManipulator) {
233  
-				$list = $item->getManipulatedData($this, $list);
234  
-			}
235  
-		}
  245
+		$list = $this->getManipulatedList();
236 246
 		
237 247
 		// Render headers, footers, etc
238 248
 		$content = array(
24  tests/forms/GridFieldTest.php
@@ -392,6 +392,22 @@ public function testCanViewOnlyOddIDs() {
392 392
 		$this->assertEquals((string)$members[1]->td[0], 'Otto Fischer', 'Second object Name should be Otto Fischer');
393 393
 		$this->assertEquals((string)$members[1]->td[1], 'otto.fischer@example.org', 'Second object Email should be otto.fischer@example.org');
394 394
 	}
  395
+
  396
+	public function testChainedDataManipulators() {
  397
+		$config = new GridFieldConfig();
  398
+		$data = new ArrayList(array(1, 2, 3, 4, 5, 6));
  399
+		$gridField = new GridField('testfield', 'testfield', $data, $config);
  400
+		$endList = $gridField->getManipulatedList();
  401
+		$this->assertEquals($endList->Count(), 6);
  402
+
  403
+		$config->addComponent(new GridFieldTest_Component2);
  404
+		$endList = $gridField->getManipulatedList();
  405
+		$this->assertEquals($endList->Count(), 12);
  406
+
  407
+		$config->addComponent(new GridFieldPaginator(10));
  408
+		$endList = $gridField->getManipulatedList();
  409
+		$this->assertEquals($endList->Count(), 10);
  410
+	}
395 411
 }
396 412
 
397 413
 class GridFieldTest_Component implements GridField_ColumnProvider, GridField_ActionProvider, TestOnly{
@@ -430,6 +446,14 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat
430 446
 	
431 447
 }
432 448
 
  449
+class GridFieldTest_Component2 implements GridField_DataManipulator, TestOnly {
  450
+	function getManipulatedData(GridField $gridField, SS_List $dataList) {
  451
+		$dataList = clone $dataList;
  452
+		$dataList->merge(new ArrayList(array(7, 8, 9, 10, 11, 12)));
  453
+		return $dataList;
  454
+	}
  455
+}
  456
+
433 457
 class GridFieldTest_Team extends DataObject implements TestOnly {
434 458
 	static $db = array(
435 459
 		'Name' => 'Varchar',

0 notes on commit 4ead89a

Please sign in to comment.
Something went wrong with that request. Please try again.