public static function Data::deduplicate in JSON:API 8.2
Returns a new, deduplicated Data object.
Parameters
\Drupal\jsonapi\JsonApiResource\Data $collection: The Data object to deduplicate.
Return value
static A new merged Data object.
File
- src/
JsonApiResource/ Data.php, line 167
Class
- Data
- Represents the `data` and `included` objects of a top-level object.
Namespace
Drupal\jsonapi\JsonApiResourceCode
public static function deduplicate(Data $collection) {
$deduplicated = [];
foreach ($collection as $resource) {
$dedupe_key = $resource
->getTypeName() . ':' . $resource
->getId();
if ($resource instanceof EntityAccessDeniedHttpException && ($error = $resource
->getError()) && !is_null($error['relationship_field'])) {
$dedupe_key .= ':' . $error['relationship_field'];
}
$deduplicated[$dedupe_key] = $resource;
}
return new static(array_values($deduplicated));
}