@@ -54,7 +54,7 @@ public function create(string $resourceClass, string $property, array $options =
54
54
[$ normalizationGroups , $ denormalizationGroups ] = $ this ->getEffectiveSerializerGroups ($ options , $ resourceClass );
55
55
56
56
$ propertyMetadata = $ this ->transformReadWrite ($ propertyMetadata , $ resourceClass , $ property , $ normalizationGroups , $ denormalizationGroups );
57
- $ propertyMetadata = $ this ->transformLinkStatus ($ propertyMetadata , $ normalizationGroups , $ denormalizationGroups );
57
+ $ propertyMetadata = $ this ->transformLinkStatus ($ propertyMetadata , $ resourceClass , $ property , $ normalizationGroups , $ denormalizationGroups );
58
58
} catch (ResourceClassNotFoundException $ e ) {
59
59
// No need to check link status if related class is not a resource
60
60
}
@@ -97,7 +97,7 @@ private function transformReadWrite(PropertyMetadata $propertyMetadata, string $
97
97
*
98
98
* @throws ResourceClassNotFoundException
99
99
*/
100
- private function transformLinkStatus (PropertyMetadata $ propertyMetadata , array $ normalizationGroups = null , array $ denormalizationGroups = null ): PropertyMetadata
100
+ private function transformLinkStatus (PropertyMetadata $ propertyMetadata , string $ resourceClass , string $ propertyName , array $ normalizationGroups = null , array $ denormalizationGroups = null ): PropertyMetadata
101
101
{
102
102
// No need to check link status if property is not readable and not writable
103
103
if (false === $ propertyMetadata ->isReadable () && false === $ propertyMetadata ->isWritable ()) {
@@ -109,6 +109,7 @@ private function transformLinkStatus(PropertyMetadata $propertyMetadata, array $
109
109
return $ propertyMetadata ;
110
110
}
111
111
112
+ $ propertyGroups = $ this ->getPropertySerializerGroups ($ resourceClass , $ propertyName );
112
113
$ relatedClass = $ type ->isCollection () && ($ collectionValueType = $ type ->getCollectionValueType ()) ? $ collectionValueType ->getClassName () : $ type ->getClassName ();
113
114
114
115
if (null === $ relatedClass ) {
@@ -119,11 +120,11 @@ private function transformLinkStatus(PropertyMetadata $propertyMetadata, array $
119
120
$ relatedGroups = $ this ->getResourceSerializerGroups ($ relatedClass );
120
121
121
122
if (null === $ propertyMetadata ->isReadableLink ()) {
122
- $ propertyMetadata = $ propertyMetadata ->withReadableLink (null !== $ normalizationGroups && !empty (array_intersect ($ normalizationGroups , $ relatedGroups )));
123
+ $ propertyMetadata = $ propertyMetadata ->withReadableLink (null !== $ normalizationGroups && !empty (array_intersect ($ propertyGroups , $ relatedGroups )) && ! empty ( array_intersect ( $ normalizationGroups , $ relatedGroups )));
123
124
}
124
125
125
126
if (null === $ propertyMetadata ->isWritableLink ()) {
126
- $ propertyMetadata = $ propertyMetadata ->withWritableLink (null !== $ denormalizationGroups && !empty (array_intersect ($ denormalizationGroups , $ relatedGroups )));
127
+ $ propertyMetadata = $ propertyMetadata ->withWritableLink (null !== $ denormalizationGroups && !empty (array_intersect ($ propertyGroups , $ relatedGroups )) && ! empty ( array_intersect ( $ denormalizationGroups , $ relatedGroups )));
127
128
}
128
129
129
130
return $ propertyMetadata ;
0 commit comments