function ResourceIdentifier::deduplicate
Same name in other branches
- 9 core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::deduplicate()
- 8.9.x core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::deduplicate()
- 10 core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::deduplicate()
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 core/
modules/ jsonapi/ src/ Controller/ EntityResource.php - Adds a relationship to a to-many relationship.
- ResourceIdentifier::areResourceIdentifiersUnique in core/
modules/ jsonapi/ src/ JsonApiResource/ ResourceIdentifier.php - Determines if an array of ResourceIdentifier objects is duplicate free.
File
-
core/
modules/ jsonapi/ 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));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.