public static function ResourceIdentifier::deduplicate in JSON:API 8.2
Deduplicates an array of ResourceIdentifier objects.
Parameters
\Drupal\jsonapi\JsonApiResource\ResourceIdentifier[] $resource_identifiers: The list of ResourceIdentifiers to deduplicate.
Return value
\Drupal\jsonapi\JsonApiResource\ResourceIdentifier[] A deduplicated array of ResourceIdentifier objects.
See also
2 calls to ResourceIdentifier::deduplicate()
- EntityResource::addToRelationshipData in src/
Controller/ EntityResource.php - Adds a relationship to a to-many relationship.
- ResourceIdentifier::areResourceIdentifiersUnique in src/
JsonApiResource/ ResourceIdentifier.php - Determines if an array of ResourceIdentifier objects is duplicate free.
File
- src/
JsonApiResource/ ResourceIdentifier.php, line 249
Class
- ResourceIdentifier
- Represents a JSON:API resource identifier object.
Namespace
Drupal\jsonapi\JsonApiResourceCode
public static function deduplicate(array $resource_identifiers) {
return array_reduce(array_slice($resource_identifiers, 1), function ($deduplicated, $current) {
assert($current instanceof static);
return array_merge($deduplicated, array_reduce($deduplicated, function ($duplicate, $previous) use ($current) {
return $duplicate ?: static::isDuplicate($previous, $current);
}, FALSE) ? [] : [
$current,
]);
}, array_slice($resource_identifiers, 0, 1));
}