You are here

public static function Link::merge in Drupal 9

Same name and namespace in other branches
  1. 8 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 170

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