diff --git a/core/modules/jsonapi/src/Controller/EntityResource.php b/core/modules/jsonapi/src/Controller/EntityResource.php index 5c86a47d70..8a7cd7bd0c 100644 --- a/core/modules/jsonapi/src/Controller/EntityResource.php +++ b/core/modules/jsonapi/src/Controller/EntityResource.php @@ -655,7 +655,7 @@ public function replaceRelationshipData(ResourceType $resource_type, EntityInter $this->validate($entity); $entity->save(); $requires_response = static::relationshipResponseRequiresBody($resource_identifiers, ResourceIdentifier::toResourceIdentifiersWithArityRequired($field_list)); - return $this->getRelationship($resource_type, $entity, $related, $request, $requires_response ? 200 : 204); + return $this->getRelationship($resource_type, $entity, $resource_type->getPublicName($related), $request, $requires_response ? 200 : 204); } /** diff --git a/core/modules/jsonapi/src/JsonApiResource/ResourceObject.php b/core/modules/jsonapi/src/JsonApiResource/ResourceObject.php index 7ed9042dd4..2e9c38d1f4 100644 --- a/core/modules/jsonapi/src/JsonApiResource/ResourceObject.php +++ b/core/modules/jsonapi/src/JsonApiResource/ResourceObject.php @@ -303,6 +303,10 @@ protected static function extractContentEntityFields(ResourceType $resource_type $is_relationship = in_array($public_field_name, $relationship_field_names, TRUE); if ($field_access_result->isAllowed()) { assert(!$is_relationship || $field_value instanceof EntityReferenceFieldItemListInterface); + // Access cacheability needs to be specially captured for the "allowed" + // case. In the other case, cacheability is captured by the + // EntityAccessDeniedException. + $entity->addCacheableDependency($field_access_result); $output[$public_field_name] = $is_relationship ? Relationship::createFromEntityReferenceField($resource_type, $field_value) : $field_value; } else { diff --git a/core/modules/jsonapi/src/Normalizer/RelationshipNormalizer.php b/core/modules/jsonapi/src/Normalizer/RelationshipNormalizer.php index 1ce4d0336e..53354af0b6 100644 --- a/core/modules/jsonapi/src/Normalizer/RelationshipNormalizer.php +++ b/core/modules/jsonapi/src/Normalizer/RelationshipNormalizer.php @@ -24,7 +24,7 @@ public function normalize($object, $format = NULL, array $context = []) { assert($object instanceof Relationship); return CacheableNormalization::aggregate([ 'data' => $this->serializer->normalize($object->getData(), $format, $context), - 'links' => $this->serializer->normalize($object->getLinks(), $format, $context), + 'links' => $this->serializer->normalize($object->getLinks(), $format, $context)->omitIfEmpty(), 'meta' => CacheableNormalization::permanent($object->getMeta())->omitIfEmpty(), ]); }