public function FieldNormalizerValue::getAllIncludes in JSON:API 8
Computes all the nested includes recursively.
Return value
array The includes and the nested includes.
Overrides FieldNormalizerValueInterface::getAllIncludes
File
- src/
Normalizer/ Value/ FieldNormalizerValue.php, line 119
Class
- FieldNormalizerValue
- Helps normalize fields in compliance with the JSON API spec.
Namespace
Drupal\jsonapi\Normalizer\ValueCode
public function getAllIncludes() {
$nested_includes = array_map(function ($include) {
return $include
->getIncludes();
}, $this
->getIncludes());
$includes = array_reduce(array_filter($nested_includes), function ($carry, $item) {
return array_merge($carry, $item);
}, $this
->getIncludes());
// Make sure we don't output duplicate includes.
return array_values(array_reduce($includes, function ($unique_includes, $include) {
$rasterized_include = $include
->rasterizeValue();
$unique_includes[$rasterized_include['data']['type'] . ':' . $rasterized_include['data']['id']] = $include;
return $unique_includes;
}, []));
}