function Link::merge

Same name in other branches
  1. 9 core/modules/jsonapi/src/JsonApiResource/Link.php \Drupal\jsonapi\JsonApiResource\Link::merge()
  2. 8.9.x 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.

1 call to Link::merge()
LinkCollection::withLink in core/modules/jsonapi/src/JsonApiResource/LinkCollection.php
Gets a new LinkCollection with the given link inserted.

File

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

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.