Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. LinkCollection.php

function 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\JsonApiResource

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal