diff --git a/src/Module/Catalog/Infrastructure/ApiPlatform/State/Provider/CategoryProvider.php b/src/Module/Catalog/Infrastructure/ApiPlatform/State/Provider/CategoryProvider.php index 97a351b..bc7f4c7 100644 --- a/src/Module/Catalog/Infrastructure/ApiPlatform/State/Provider/CategoryProvider.php +++ b/src/Module/Catalog/Infrastructure/ApiPlatform/State/Provider/CategoryProvider.php @@ -4,11 +4,14 @@ declare(strict_types=1); namespace App\Module\Catalog\Infrastructure\ApiPlatform\State\Provider; +use ApiPlatform\Doctrine\Orm\Paginator; use ApiPlatform\Metadata\CollectionOperationInterface; use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\Pagination\Pagination; use ApiPlatform\State\ProviderInterface; use App\Module\Catalog\Domain\Entity\Category; use App\Module\Catalog\Domain\Repository\CategoryRepositoryInterface; +use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator; use Symfony\Component\DependencyInjection\Attribute\Autowire; /** @@ -29,18 +32,32 @@ final class CategoryProvider implements ProviderInterface public function __construct( #[Autowire(service: 'App\Module\Catalog\Infrastructure\Doctrine\DoctrineCategoryRepository')] private readonly CategoryRepositoryInterface $repository, + private readonly Pagination $pagination, ) {} - public function provide(Operation $operation, array $uriVariables = [], array $context = []): Category|iterable|null + public function provide(Operation $operation, array $uriVariables = [], array $context = []): Category|iterable|Paginator|null { $includeDeleted = $this->readIncludeDeleted($context); if ($operation instanceof CollectionOperationInterface) { - return $this->repository - ->createListQueryBuilder($includeDeleted) - ->getQuery() - ->getResult() - ; + $qb = $this->repository->createListQueryBuilder($includeDeleted); + + // Echappatoire ?pagination=false : retourne la collection complete sans Paginator. + // Utile pour les drawers Role/Permission/Site/CategoryType qui alimentent un