mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX #3919: Fix DataObject::dbObject() for decorated fields
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@75150 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
8fcdcfa2eb
commit
b165bde578
@ -211,19 +211,19 @@ class ViewableData extends Object implements IteratorAggregate {
|
|||||||
public function buildCastingHelperCache(&$cache) {
|
public function buildCastingHelperCache(&$cache) {
|
||||||
$class = $this->class ? $this->class : get_class($this);
|
$class = $this->class ? $this->class : get_class($this);
|
||||||
$classes = ClassInfo::ancestry($class);
|
$classes = ClassInfo::ancestry($class);
|
||||||
|
|
||||||
foreach($classes as $componentClass) {
|
foreach($classes as $componentClass) {
|
||||||
if($componentClass == "ViewableData") $isViewableData = true;
|
if($componentClass == "ViewableData") $isViewableData = true;
|
||||||
if($componentClass == "DataObject") $isDataObject = true;
|
if($componentClass == "DataObject") $isDataObject = true;
|
||||||
|
|
||||||
if(isset($isDataObject) && $isDataObject) {
|
if(isset($isDataObject) && $isDataObject) {
|
||||||
$fields = eval("return {$componentClass}::\$db;");
|
$fields = Object::uninherited_static($componentClass, 'db');
|
||||||
if($fields) foreach($fields as $fieldName => $fieldSchema) {
|
if($fields) foreach($fields as $fieldName => $fieldSchema) {
|
||||||
$cache[$fieldName] = ViewableData::castingObjectCreatorPair($fieldSchema);
|
$cache[$fieldName] = ViewableData::castingObjectCreatorPair($fieldSchema);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isset($isViewableData) && $isViewableData) {
|
if(isset($isViewableData) && $isViewableData) {
|
||||||
$fields = eval("return {$componentClass}::\$casting;");
|
$fields = Object::uninherited_static($componentClass, 'casting');
|
||||||
if($fields) foreach($fields as $fieldName => $fieldSchema) {
|
if($fields) foreach($fields as $fieldName => $fieldSchema) {
|
||||||
$cache[$fieldName] = ViewableData::castingObjectCreatorPair($fieldSchema);
|
$cache[$fieldName] = ViewableData::castingObjectCreatorPair($fieldSchema);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,15 @@ class DataObjectDecoratorTest extends SapphireTest {
|
|||||||
'Defaults can be populated through decorator'
|
'Defaults can be populated through decorator'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that DataObject::dbObject() works for fields applied by a decorator
|
||||||
|
*/
|
||||||
|
function testDbObjectOnDecoratedFields() {
|
||||||
|
$member = $this->objFromFixture('DataObjectDecoratorTest_Member', 'member1');
|
||||||
|
$this->assertNotNull($member->dbObject('Website'));
|
||||||
|
$this->assertType('Text', $member->dbObject('Website'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataObjectDecoratorTest_Member extends DataObject implements TestOnly {
|
class DataObjectDecoratorTest_Member extends DataObject implements TestOnly {
|
||||||
|
@ -33,6 +33,10 @@ Member:
|
|||||||
Groups: =>Group.admingroup
|
Groups: =>Group.admingroup
|
||||||
websiteuser:
|
websiteuser:
|
||||||
Email: websiteuser@test.com
|
Email: websiteuser@test.com
|
||||||
|
DataObjectDecoratorTest_Member:
|
||||||
|
member1:
|
||||||
|
Name: Sam
|
||||||
|
Website: http://www.example.org
|
||||||
DataObjectDecoratorTest_MyObject:
|
DataObjectDecoratorTest_MyObject:
|
||||||
object1:
|
object1:
|
||||||
Title: Object 1
|
Title: Object 1
|
@ -69,6 +69,17 @@ class ObjectStaticTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that calls to Object::add_static() will update the data returned by Object::uninherited_static()
|
||||||
|
*/
|
||||||
|
public function testAddStaticFollowedByUnheritedCall() {
|
||||||
|
Object::add_static_var('ObjectStaticTest_First', 'first', array('test_1b'));
|
||||||
|
Object::add_static_var('ObjectStaticTest_Second', 'first', array('test_2b'));
|
||||||
|
|
||||||
|
$this->assertContains('test_1b', Object::uninherited_static('ObjectStaticTest_First', 'first'));
|
||||||
|
$this->assertContains('test_2b', Object::uninherited_static('ObjectStaticTest_Second', 'first'));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**#@+
|
/**#@+
|
||||||
|
Loading…
x
Reference in New Issue
Block a user