From 08f8ff77882531cbffef75d1c0afb535e50c796c Mon Sep 17 00:00:00 2001 From: tristan Date: Fri, 29 May 2026 15:02:00 +0200 Subject: [PATCH] fix(catalog) : CategoryProvider retourne un Paginator ORM + supporte ?pagination=false --- .../State/Provider/CategoryProvider.php | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) 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