mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API Adds getManipulatedList() method to GridField to get the SS_List after applying Manipulators
This commit is contained in:
parent
19bdd4b4c5
commit
4ead89a4d0
@ -193,6 +193,21 @@ class GridField extends FormField {
|
||||
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 @@ class GridField extends FormField {
|
||||
$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 @@ class GridFieldTest extends SapphireTest {
|
||||
$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 @@ class GridFieldTest_Component implements GridField_ColumnProvider, GridField_Act
|
||||
|
||||
}
|
||||
|
||||
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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user