Skip to content

How to keep pagination information when using output DTOs? #6474

Answered by norkunas
bpolaszek asked this question in Q&A
Discussion options

You must be logged in to vote

You can preserve hydra:totalItems with ArrayPaginator:

namespace App\State;

use ApiPlatform\Doctrine\Orm\State\CollectionProvider;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\Pagination\ArrayPaginator
use ApiPlatform\State\Pagination\Pagination;
use ApiPlatform\State\ProviderInterface;
use App\Entity\BookOutput;

final readonly class BookCollectionProvider implements ProviderInterface
{
    public function __construct(
        private CollectionProvider $collectionProvider,
        private Pagination $pagination,
    ) {
    }

    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ArrayPaginator
    {
        $results = $this->col…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bpolaszek
Comment options

Answer selected by bpolaszek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants