-
-
Notifications
You must be signed in to change notification settings - Fork 976
Closed
Labels
Description
Hi,
i have a problem.
I can not figure it out how to apply filters for custom collection data provider. In this examples provider does not do anything but filters are problem.
This is my resource file:
resources:
LocationBundle\Entity\Location:
itemOperations:
get:
method: 'GET'
normalization_context:
groups: ['location-item']
collectionOperations:
get:
method: 'GET'
normalization_context:
groups: ['location-list']
attributes:
filters: ['location.search', 'location.boolean']
My provider:
class LocationCollectionDataProvider implements CollectionDataProviderInterface
{
/**
* @var EntityRepository
*/
private $locationRepository;
public function __construct(EntityRepository $locationRepository)
{
$this->locationRepository = $locationRepository;
}
public function getCollection(string $resourceClass, string $operationName = null)
{
if (Location::class !== $resourceClass) {
throw new ResourceClassNotSupportedException();
}
return $this->locationRepository->findAll();
}
}
services:
location.repository:
class: Doctrine\ORM\EntityRepository
factory: ["@doctrine.orm.entity_manager", getRepository]
arguments: [ LocationBundle\Entity\Location ]
location.collection_data_provider:
class: 'LocationBundle\DataProvider\LocationCollectionDataProvider'
public: false
arguments: [ "@location.repository" ]
tags:
- { name: 'api_platform.collection_data_provider', priority: 2 }
Tnx! :D
fulopattila122, nescim and bravik