mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
FIX: ViewableData::obj() would sometimes return an empty object
For instance, this happens when these criteria are met: 1) No casting has been specified for a method in $casting. 2) A template accesses the field without any casting 3) Any casts by the template will now yield an empty object. After a brief look at the commit history, it can seem like this bug is several years old, unless it is a side-effect of other changes in the code. == Steps to reproduce == Add two methods to be accessed by a template. Make sure you do not define an entry in $casting for them: public function Testus() { return "Te<x>t1"; } public function Testus2() { return "Te<x>t2"; } Add this to a template: <p> First access:<br /> "$Testus" : "$Testus.XML"<br /> "$Testus2.XML" : "$Testus2"<br /> </p> <p> Second access:<br /> "$Testus" : "$Testus.XML"<br /> "$Testus2.XML" : "$Testus2"<br /> </p> Open the page in a browser, and you will get: First access: "Tet1" : "" "Te<x>t2" : "Tet2" Second access: "Tet1" : "" "" : "Tet2" We see that any cast can yield an empty string.
This commit is contained in:
parent
e908613c47
commit
b52087105c
@ -383,7 +383,9 @@ class ViewableData extends Object implements IteratorAggregate {
|
|||||||
|
|
||||||
if(!is_object($value) && $forceReturnedObject) {
|
if(!is_object($value) && $forceReturnedObject) {
|
||||||
$default = Config::inst()->get('ViewableData', 'default_cast', Config::FIRST_SET);
|
$default = Config::inst()->get('ViewableData', 'default_cast', Config::FIRST_SET);
|
||||||
$value = new $default($fieldName);
|
$castedValue = new $default($fieldName);
|
||||||
|
$castedValue->setValue($value);
|
||||||
|
$value = $castedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user