function Link::merge

Same name in other branches
  1. 9 core/modules/jsonapi/src/JsonApiResource/Link.php \Drupal\jsonapi\JsonApiResource\Link::merge()
  2. 10 core/modules/jsonapi/src/JsonApiResource/Link.php \Drupal\jsonapi\JsonApiResource\Link::merge()
  3. 11.x core/modules/jsonapi/src/JsonApiResource/Link.php \Drupal\jsonapi\JsonApiResource\Link::merge()

Merges two equivalent links into one link with the merged cacheability.

The links must share the same URI, link relation type and attributes.

Parameters

\Drupal\jsonapi\JsonApiResource\Link $a: The first link.

\Drupal\jsonapi\JsonApiResource\Link $b: The second link.

Return value

static A new JSON:API Link object with the cacheability of both links merged.

2 calls to Link::merge()
LinkCollection::withLink in core/modules/jsonapi/src/JsonApiResource/LinkCollection.php
Gets a new LinkCollection with the given link inserted.
LinkTest::testLinkMerge in core/modules/jsonapi/tests/src/Unit/JsonApiResource/LinkTest.php
@covers ::merge @dataProvider linkMergeProvider

File

core/modules/jsonapi/src/JsonApiResource/Link.php, line 200

Class

Link
Represents an RFC8288 based link.

Namespace

Drupal\jsonapi\JsonApiResource

Code

public static function merge(Link $a, Link $b) {
    assert(static::compare($a, $b) === 0, 'Only equivalent links can be merged.');
    $merged_cacheability = (new CacheableMetadata())->addCacheableDependency($a)
        ->addCacheableDependency($b);
    return new static($merged_cacheability, $a->getUri(), $a->getLinkRelationType(), $a->getTargetAttributes());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.