@@ -50,7 +50,8 @@ public function __construct(
5050 private readonly ResourceMetadataCollectionFactoryInterface $ resourceMetadataCollectionFactory ,
5151 private readonly ?ProviderInterface $ parameterProvider ,
5252 private readonly string $ itemsPerPageParameterName ,
53- ) {}
53+ ) {
54+ }
5455
5556 public function supportsTransformation ($ data , string $ to , array $ context = []): bool
5657 {
@@ -87,7 +88,7 @@ private function transform(Collection $object): Collection
8788 }
8889
8990 // Build context
90- $ collectionContext = [ 'operation ' => $ getCollectionOperation , 'resource_class ' => $ resourceClass ];
91+ $ collectionContext = ['operation ' => $ getCollectionOperation , 'resource_class ' => $ resourceClass ];
9192
9293 // Build filters
9394 $ filters = [];
@@ -113,9 +114,18 @@ private function transform(Collection $object): Collection
113114 $ collectionContext += $ normalizationContext = $ this ->serializerContextBuilder ->createFromRequest ($ request , true , $ attributes );
114115 try {
115116 $ uriVariables = $ this ->getOperationUriVariables ($ getCollectionOperation , $ parameters , $ resourceClass );
116- $ this ->parameterProvider ->provide ($ getCollectionOperation , $ uriVariables , [ ...$ collectionContext , 'request ' => clone $ request , 'uri_variables ' => $ uriVariables ]);
117+ $ clonedRequest = clone $ request ;
118+ if ($ defaultQueryParams ) {
119+ foreach ($ defaultQueryParams as $ key => $ defaultQueryParam ) {
120+ if (!$ clonedRequest ->query ->has ($ key )) {
121+ $ clonedRequest ->query ->set ($ key , $ defaultQueryParam );
122+ }
123+ }
124+ $ clonedRequest ->attributes ->set ('_api_query_parameters ' , $ clonedRequest ->query ->all ());
125+ }
126+ $ this ->parameterProvider ->provide ($ getCollectionOperation , $ uriVariables , [...$ collectionContext , 'request ' => $ clonedRequest , 'uri_variables ' => $ uriVariables ]);
117127 // Operation $operation, array $uriVariables = [], array $context = []
118- $ collectionData = $ this ->provider ->provide ($ getCollectionOperation , $ uriVariables , [ ... $ collectionContext, ' request ' => $ request , ' uri_variables ' => $ uriVariables ] );
128+ $ collectionData = $ this ->provider ->provide ($ getCollectionOperation , $ uriVariables , $ collectionContext );
119129 } catch (InvalidIdentifierException $ e ) {
120130 throw new NotFoundHttpException ('Invalid identifier value or configuration. ' , $ e );
121131 }
0 commit comments