@@ -670,7 +670,7 @@ protected function getAttributeValue(object $object, string $attribute, ?string
670
670
&& ($ className = $ collectionValueType ->getClassName ())
671
671
&& $ this ->resourceClassResolver ->isResourceClass ($ className )
672
672
) {
673
- $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className ), $ attribute , $ format );
673
+ $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className, $ propertyMetadata ), $ attribute , $ format );
674
674
675
675
// @see ApiPlatform\Hal\Serializer\ItemNormalizer:getComponents logic for intentional duplicate content
676
676
// @see ApiPlatform\JsonApi\Serializer\ItemNormalizer:getComponents logic for intentional duplicate content
@@ -707,7 +707,7 @@ protected function getAttributeValue(object $object, string $attribute, ?string
707
707
($ className = $ type ->getClassName ())
708
708
&& $ this ->resourceClassResolver ->isResourceClass ($ className )
709
709
) {
710
- $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className ), $ attribute , $ format );
710
+ $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className, $ propertyMetadata ), $ attribute , $ format );
711
711
unset($ childContext ['iri ' ], $ childContext ['uri_variables ' ], $ childContext ['item_uri_template ' ]);
712
712
if ('jsonld ' === $ format && $ uriTemplate = $ propertyMetadata ->getUriTemplate ()) {
713
713
$ operation = $ this ->resourceMetadataCollectionFactory ->create ($ className )->getOperation (
@@ -749,22 +749,18 @@ protected function getAttributeValue(object $object, string $attribute, ?string
749
749
750
750
// Anonymous resources
751
751
if ($ className ) {
752
- $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className ), $ attribute , $ format );
753
- $ childContext ['output ' ]['gen_id ' ] = $ propertyMetadata ->getGenId () ?? true ;
754
-
752
+ $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className , $ propertyMetadata ), $ attribute , $ format );
755
753
$ attributeValue = $ this ->propertyAccessor ->getValue ($ object , $ attribute );
756
754
757
755
return $ this ->serializer ->normalize ($ attributeValue , $ format , $ childContext );
758
756
}
759
757
760
758
if ('array ' === $ type ->getBuiltinType ()) {
761
759
if ($ className = ($ type ->getCollectionValueTypes ()[0 ] ?? null )?->getClassName()) {
762
- $ context = $ this ->createOperationContext ($ context , $ className );
760
+ $ context = $ this ->createOperationContext ($ context , $ className, $ propertyMetadata );
763
761
}
764
762
765
763
$ childContext = $ this ->createChildContext ($ context , $ attribute , $ format );
766
- $ childContext ['output ' ]['gen_id ' ] = $ propertyMetadata ->getGenId () ?? true ;
767
-
768
764
$ attributeValue = $ this ->propertyAccessor ->getValue ($ object , $ attribute );
769
765
770
766
return $ this ->serializer ->normalize ($ attributeValue , $ format , $ childContext );
@@ -820,12 +816,12 @@ protected function normalizeCollectionOfRelations(ApiProperty $propertyMetadata,
820
816
*/
821
817
protected function normalizeRelation (ApiProperty $ propertyMetadata , ?object $ relatedObject , string $ resourceClass , ?string $ format , array $ context ): \ArrayObject |array |string |null
822
818
{
823
- if (null === $ relatedObject || !empty ($ context ['attributes ' ]) || $ propertyMetadata ->isReadableLink ()) {
819
+ if (null === $ relatedObject || !empty ($ context ['attributes ' ]) || $ propertyMetadata ->isReadableLink () || false === ( $ context [ ' output ' ][ ' gen_id ' ] ?? true ) ) {
824
820
if (!$ this ->serializer instanceof NormalizerInterface) {
825
821
throw new LogicException (\sprintf ('The injected serializer must be an instance of "%s". ' , NormalizerInterface::class));
826
822
}
827
823
828
- $ relatedContext = $ this ->createOperationContext ($ context , $ resourceClass );
824
+ $ relatedContext = $ this ->createOperationContext ($ context , $ resourceClass, $ propertyMetadata );
829
825
$ normalizedRelatedObject = $ this ->serializer ->normalize ($ relatedObject , $ format , $ relatedContext );
830
826
if (!\is_string ($ normalizedRelatedObject ) && !\is_array ($ normalizedRelatedObject ) && !$ normalizedRelatedObject instanceof \ArrayObject && null !== $ normalizedRelatedObject ) {
831
827
throw new UnexpectedValueException ('Expected normalized relation to be an IRI, array, \ArrayObject or null ' );
@@ -917,7 +913,7 @@ private function createAndValidateAttributeValue(string $attribute, mixed $value
917
913
&& $ this ->resourceClassResolver ->isResourceClass ($ className )
918
914
) {
919
915
$ resourceClass = $ this ->resourceClassResolver ->getResourceClass (null , $ className );
920
- $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ resourceClass ), $ attribute , $ format );
916
+ $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ resourceClass, $ propertyMetadata ), $ attribute , $ format );
921
917
922
918
try {
923
919
return $ this ->denormalizeRelation ($ attribute , $ propertyMetadata , $ resourceClass , $ value , $ format , $ childContext );
0 commit comments