protected function JsonapiParse::parseJsonContent in JSON:API Include 8
Parse json content.
Parameters
object $response: The jsonapi object.
Return value
mixed Parse result.
1 call to JsonapiParse::parseJsonContent()
- JsonapiParse::parse in src/
JsonapiParse.php - Parse json api.
File
- src/
JsonapiParse.php, line 213
Class
- JsonapiParse
- Class JsonapiParse.
Namespace
Drupal\jsonapi_includeCode
protected function parseJsonContent($response) {
if (is_string($response)) {
$json = Json::decode($response);
}
elseif (is_object($response)) {
$json = $response;
}
else {
return $response;
}
if (NestedArray::getValue($json, [
'jsonapi',
'parsed',
])) {
return $json;
}
if (isset($json['errors']) || empty($json['data'])) {
return $json;
}
$this->included = $this
->groupIncludes($json);
$data = [];
if (!$this
->isAssoc($json['data'])) {
foreach ($json['data'] as $item) {
$data[] = $this
->parseResource($item);
}
}
else {
$data = $this
->parseResource($json['data']);
}
if (isset($json['included'])) {
unset($json['included']);
}
$json['jsonapi']['parsed'] = TRUE;
$json['data'] = $data;
return $json;
}