mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Allow object-methods to be used as columns in TableListField
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60448 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
668dc7c6d2
commit
b5001bc906
@ -427,7 +427,7 @@ JS
|
||||
|
||||
$SNG = singleton($this->sourceClass);
|
||||
foreach($this->FieldList() as $k=>$title){
|
||||
if(!$SNG->hasField($k) && !$SNG->hasMethod('get' . $k) && !strpos($k, "."))
|
||||
if(!$SNG->hasField($k) && !$SNG->hasMethod('get' . $k) && !$SNG->hasMethod($k) && !strpos($k, "."))
|
||||
$query->select[] = $k;
|
||||
}
|
||||
}
|
||||
|
39
tests/forms/TableListFieldTest.php
Normal file
39
tests/forms/TableListFieldTest.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
class TableListFieldTest extends SapphireTest {
|
||||
static $fixture_file = 'sapphire/tests/forms/TableListFieldTest.yml';
|
||||
|
||||
function testCanReferenceCustomMethodsAndFiledsOnObject() {
|
||||
$table = new TableListField("Tester", "TableListFieldTest_Obj", array(
|
||||
"A" => "Col A",
|
||||
"B" => "Col B",
|
||||
"C" => "Col C",
|
||||
"D" => "Col D",
|
||||
"E" => "Col E",
|
||||
));
|
||||
|
||||
$result = $table->FieldHolder();
|
||||
|
||||
// Do a quick check to ensure that some of the D() and getE() values got through
|
||||
$this->assertRegExp('/>\s*a2\s*</', $result);
|
||||
$this->assertRegExp('/>\s*a2\/b2\/c2\s*</', $result);
|
||||
$this->assertRegExp('/>\s*a2-e</', $result);
|
||||
}
|
||||
}
|
||||
|
||||
class TableListFieldTest_Obj extends DataObject implements TestOnly {
|
||||
static $db = array(
|
||||
"A" => "Varchar",
|
||||
"B" => "Varchar",
|
||||
"C" => "Varchar",
|
||||
);
|
||||
|
||||
function D() {
|
||||
return $this->A . '/' . $this->B . '/' . $this->C;
|
||||
}
|
||||
|
||||
function getE() {
|
||||
return $this->A . '-e';
|
||||
}
|
||||
|
||||
}
|
10
tests/forms/TableListFieldTest.yml
Normal file
10
tests/forms/TableListFieldTest.yml
Normal file
@ -0,0 +1,10 @@
|
||||
TableListFieldTest_Obj:
|
||||
one:
|
||||
A: a1
|
||||
B: b1
|
||||
C: c1
|
||||
two:
|
||||
A: a2
|
||||
B: b2
|
||||
C: c2
|
||||
|
Loading…
Reference in New Issue
Block a user