function Relationship::getMergedLinks

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

Overrides TopLevelDataInterface::getMergedLinks

File

core/modules/jsonapi/src/JsonApiResource/Relationship.php, line 192

Class

Relationship
Represents references from one resource object to other resource object(s).

Namespace

Drupal\jsonapi\JsonApiResource

Code

public function getMergedLinks(LinkCollection $top_level_links) {
    // When directly fetching a relationship object, the relationship object's
    // links become the top-level object's links unless they've been
    // overridden. Overrides are especially important for the `self` link, which
    // must match the link that generated the response. For example, the
    // top-level `self` link might have an `include` query parameter that would
    // be lost otherwise.
    // See https://jsonapi.org/format/#fetching-relationships-responses-200 and
    // https://jsonapi.org/format/#document-top-level.
    return LinkCollection::merge($top_level_links, $this->getLinks()
        ->filter(function ($key) use ($top_level_links) {
        return !$top_level_links->hasLinkWithKey($key);
    })
        ->withContext($top_level_links->getContext()));
}

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