public function RelationshipNormalizerValue::rasterizeValue in JSON:API 8
Get the rasterized value.
Return value
mixed The value.
Overrides FieldNormalizerValue::rasterizeValue
File
- src/
Normalizer/ Value/ RelationshipNormalizerValue.php, line 71
Class
- RelationshipNormalizerValue
- Helps normalize relationships in compliance with the JSON API spec.
Namespace
Drupal\jsonapi\Normalizer\ValueCode
public function rasterizeValue() {
$links = $this
->getLinks($this->fieldName);
// Empty 'to-one' relationships must be NULL.
// Empty 'to-many' relationships must be an empty array.
// @link http://jsonapi.org/format/#document-resource-object-linkage
$data = parent::rasterizeValue() ?: [];
if ($this->cardinality === 1) {
return empty($data) ? [
'data' => NULL,
'links' => $links,
] : [
'data' => $data,
'links' => $links,
];
}
else {
return [
'data' => static::ensureUniqueResourceIdentifierObjects($data),
'links' => $links,
];
}
}