- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 936
Closed
Description
API Platform version(s) affected: 4.2.1
Description
I’m not sure whether ReadLinkParameterProvider was intended to be used within a GetCollection.
I wanted to filter a collection of custom api resource with a value coming from an entity
How to reproduce
Lets say we have the this "entity" resource
#[Get(
    provider: [self::class, 'provide']
)]
class Instrument
{
    public string $id;
    public string $name;
    public static function provide(
        Operation $operation,
        array     $uriVariables = [],
        array     $context = []
    ): object|array|null {
        $instrumentId = $uriVariables['id'] ?? null;
        $instruments = [
            1 => 'Guitar',
            2 => 'Piano',
            3 => 'Drums',
        ];
        if (!isset($instruments[$instrumentId])) {
            return null;
        }
        $instrument = new self();
        $instrument->id = $instrumentId;
        $instrument->name = $instruments[$instrumentId];
        return $instrument;
    }
}
And the api resource we want to call to filter "announce" based on the "instrument" id.
#[GetCollection(
    // output: AnnounceResult::class,
    parameters: [
        'instrument' => new QueryParameter(
            provider: ReadLinkParameterProvider::class,
            extraProperties: [
                'resource_class' => Instrument::class,
            ]
        )
    ],
    provider: [self::class, 'provide']
)]
class Announce
{
    public static function provide(
        Operation $operation,
        array     $uriVariables = [],
        array     $context = []
    ): object|array|null {
        dump($operation->getParameters()->get('instrument')->getValue());
        return [];
    }
}
When I call it https://127.0.0.1:8000/api/announces?page=1&instrument=1
I got this error  :
  "detail": "Provider \"ApiPlatform\\State\\ParameterProvider\\ReadLinkParameterProvider\" not found on operation \"_api_/announces{._format}_get_collection\"",
It does works with provider: IriConverterParameterProvider::class
example : https://127.0.0.1:8000/api/announces?page=1&instrument=/api/instruments/1
Metadata
Metadata
Assignees
Labels
No labels