I'm using API Platform 3.1. When you've got an entity with a ApiFilter
, Hydra will give some information about all fields with a filter. In this simple example it will give the name of the field (createdAt
):
class Entity
{
#[ApiFilter(DateFilter::class, properties: ['createdAt'])]
protected ?DateTimeInterface $createdAt = null;
}
'hydra:search': {
"@type": "hydra:IriTemplate"
"hydra:mapping": {
"@type": "IriTemplateMapping",
"variable": "createdAt[after]",
"property": "createdAt",
"required": false
}
}
This information can be used to populate search fields client side, like Swagger does:
Now I want this information to generate a form with fields that can be used to sort or filter. But I want not only the field names, but some extra information about how the filter can be used. For example: a date field createdAt
should render a slightly different datepicker than a birthdate
field.
I've already tried extending the Hydra context as described in API Platform's documentation:
#[ApiResource(operations: [
new Get(hydraContext: ['foo' => 'bar'])
])
But I didn't found foo/bar in my /api/items
response.
Is there a way to add some information to the Hydra model which I can use in my application?