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

Breadcrumb

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

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

API Navigation

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