mirror of
https://github.com/silverstripe/silverstripe-restfulserver
synced 2024-10-22 12:05:58 +00:00
FIX Respect new typehints (#133)
This commit is contained in:
parent
9ee11bfaa1
commit
f73c5b8592
@ -89,7 +89,12 @@ class JSONDataFormatter extends DataFormatter
|
||||
continue;
|
||||
}
|
||||
|
||||
$fieldValue = JSONDataFormatter::cast($obj->obj($fieldName));
|
||||
$dbField = $obj->obj($fieldName);
|
||||
if ($dbField) {
|
||||
$fieldValue = JSONDataFormatter::cast($dbField);
|
||||
} else {
|
||||
$fieldValue = null;
|
||||
}
|
||||
$mappedFieldName = $this->getFieldAlias($className, $fieldName);
|
||||
$serobj->$mappedFieldName = $fieldValue;
|
||||
}
|
||||
@ -117,10 +122,11 @@ class JSONDataFormatter extends DataFormatter
|
||||
? $this->sanitiseClassName($relClass) . '/' . $obj->$fieldName
|
||||
: $this->sanitiseClassName($className) . "/$id/$relName";
|
||||
$href = Director::absoluteURL($rel);
|
||||
$dbField = $obj->obj($fieldName);
|
||||
$serobj->$relName = ArrayData::array_to_object(array(
|
||||
"className" => $relClass,
|
||||
"href" => "$href.json",
|
||||
"id" => JSONDataFormatter::cast($obj->obj($fieldName))
|
||||
"id" => $dbField ? JSONDataFormatter::cast($dbField): ''
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ class XMLDataFormatter extends DataFormatter
|
||||
if ($fields && !in_array($fieldName, $fields ?? [])) {
|
||||
continue;
|
||||
}
|
||||
$fieldValue = $obj->obj($fieldName)->forTemplate();
|
||||
$fieldValue = $obj->obj($fieldName)?->forTemplate();
|
||||
if (!mb_check_encoding($fieldValue, 'utf-8')) {
|
||||
$fieldValue = "(data is badly encoded)";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user