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:
Sam Minnee 2008-08-12 00:12:29 +00:00
parent 668dc7c6d2
commit b5001bc906
3 changed files with 50 additions and 1 deletions

View File

@ -427,7 +427,7 @@ JS
$SNG = singleton($this->sourceClass); $SNG = singleton($this->sourceClass);
foreach($this->FieldList() as $k=>$title){ 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; $query->select[] = $k;
} }
} }

View 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';
}
}

View File

@ -0,0 +1,10 @@
TableListFieldTest_Obj:
one:
A: a1
B: b1
C: c1
two:
A: a2
B: b2
C: c2