public static function LinkCollection::merge in Drupal 9
Same name and namespace in other branches
- 8 core/modules/jsonapi/src/JsonApiResource/LinkCollection.php \Drupal\jsonapi\JsonApiResource\LinkCollection::merge()
Merges two LinkCollections.
Parameters
\Drupal\jsonapi\JsonApiResource\LinkCollection $a: The first link collection.
\Drupal\jsonapi\JsonApiResource\LinkCollection $b: The second link collection.
Return value
\Drupal\jsonapi\JsonApiResource\LinkCollection A new LinkCollection with the links of both inputs.
1 call to LinkCollection::merge()
- Relationship::getMergedLinks in core/
modules/ jsonapi/ src/ JsonApiResource/ Relationship.php - Merges the object's links with the top-level links.
File
- core/
modules/ jsonapi/ src/ JsonApiResource/ LinkCollection.php, line 171
Class
- LinkCollection
- Contains a set of JSON:API Link objects.
Namespace
Drupal\jsonapi\JsonApiResourceCode
public static function merge(LinkCollection $a, LinkCollection $b) {
assert($a
->getContext() === $b
->getContext());
$merged = new LinkCollection([], $a
->getContext());
foreach ($a as $key => $links) {
$merged = array_reduce($links, function (self $merged, Link $link) use ($key) {
return $merged
->withLink($key, $link);
}, $merged);
}
foreach ($b as $key => $links) {
$merged = array_reduce($links, function (self $merged, Link $link) use ($key) {
return $merged
->withLink($key, $link);
}, $merged);
}
return $merged;
}