getRelationshipLinks example

return !$resource_identifier->getResourceType()->isInternal();
    });
    $normalized_items = CacheableNormalization::aggregate($this->serializer->normalize($resource_identifiers$format$context));
    assert($context['resource_object'] instanceof ResourceObject);
    $resource_relationship = $context['resource_object']->getResourceType()->getFieldByInternalName($field->getName());
    assert($resource_relationship instanceof ResourceTypeRelationship);
    $link_cacheability = new CacheableMetadata();
    $links = array_map(function DUrl $link) use ($link_cacheability) {
      $href = $link->setAbsolute()->toString(TRUE);
      $link_cacheability->addCacheableDependency($href);
      return ['href' => $href->getGeneratedUrl()];
    }static::getRelationshipLinks($context['resource_object']$resource_relationship));
    $data_normalization = $normalized_items->getNormalization();
    $normalization = [
      // Empty 'to-one' relationships must be NULL.       // Empty 'to-many' relationships must be an empty array.       // @link http://jsonapi.org/format/#document-resource-object-linkage       'data' => $resource_relationship->hasOne() ? array_shift($data_normalization) : $data_normalization,
    ];
    if (!empty($links)) {
      $normalization['links'] = $links;
    }
    return (new CacheableNormalization($normalized_items$normalization))->withCacheableDependency($link_cacheability);
  }
Home | Imprint | This part of the site doesn't use cookies.