Skip to content

Commit

Permalink
FIX Respect new typehints (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Aug 29, 2024
1 parent 9ee11bf commit f73c5b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/DataFormatter/JSONDataFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ public function convertDataObjectToJSONObject(DataObjectInterface $obj, $fields
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;
}
Expand Down Expand Up @@ -117,10 +122,11 @@ public function convertDataObjectToJSONObject(DataObjectInterface $obj, $fields
? $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): ''
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/DataFormatter/XMLDataFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function convertDataObjectWithoutHeader(DataObject $obj, $fields = null,
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)";
}
Expand Down

0 comments on commit f73c5b8

Please sign in to comment.