You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/filters.md
-36Lines changed: 0 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -1006,42 +1006,6 @@ final class UserFilterConfigurator
1006
1006
1007
1007
Done: Doctrine will automatically filter all "UserAware" entities!
1008
1008
1009
-
### Overriding Extraction of Properties from the Request
1010
-
1011
-
You can change the way the filter parameters are extracted from the request. This can be done by overriding the `extractProperties(\Symfony\Component\HttpFoundation\Request $request)`
1012
-
method.
1013
-
1014
-
In the following example, we will completely change the syntax of the order filter to be the following: `?filter[order][property]`
1015
-
1016
-
```php
1017
-
<?php
1018
-
// api/src/Filter/CustomOrderFilter.php
1019
-
1020
-
namespace App\Filter;
1021
-
1022
-
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
1023
-
use Symfony\Component\HttpFoundation\Request;
1024
-
1025
-
final class CustomOrderFilter extends OrderFilter
1026
-
{
1027
-
protected function extractProperties(Request $request): array
1028
-
{
1029
-
return $request->query->get('filter[order]', []);
1030
-
}
1031
-
}
1032
-
```
1033
-
1034
-
Finally, register the custom filter:
1035
-
1036
-
```yaml
1037
-
# api/config/services.yaml
1038
-
services:
1039
-
# ...
1040
-
'App\Filter\CustomOrderFilter': ~
1041
-
# Uncomment only if autoconfiguration isn't enabled
1042
-
#tags: [ 'api_platform.filter' ]
1043
-
```
1044
-
1045
1009
## ApiFilter Annotation
1046
1010
1047
1011
The annotation can be used on a `property` or on a `class`.
0 commit comments