Skip to content

Commit

Permalink
Allow to customize default pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Mar 11, 2024
1 parent 256ee3e commit 1e05088
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/services/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Webgriffe\SyliusElasticsearchPlugin\Controller\ElasticsearchController;

return static function (ContainerConfigurator $containerConfigurator) {
$parameters = $containerConfigurator->parameters();
$parameters->set('webgriffe.sylius_elasticsearch_plugin.taxon_default_page_limit', 3);

$services = $containerConfigurator->services();

$services->set('webgriffe.sylius_elasticsearch_plugin.controller.elasticsearch', ElasticsearchController::class)
Expand All @@ -22,6 +25,7 @@
service('webgriffe.sylius_elasticsearch_plugin.mapper.query_result'),
service('event_dispatcher'),
service('webgriffe.sylius_elasticsearch_plugin.helper.sort'),
param('webgriffe.sylius_elasticsearch_plugin.taxon_default_page_limit'),
])
->call('setContainer', [service('service_container')])
->tag('controller.service_arguments')
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/ElasticsearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function __construct(
private readonly QueryResultMapperInterface $queryResultMapper,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly SortHelperInterface $sortHelper,
private readonly int $taxonDefaultPageLimit,
) {
}

Expand Down Expand Up @@ -129,7 +130,7 @@ public function taxonAction(Request $request, string $slug): Response
/** @var array<string, string> $sorting */
$sorting = $request->query->all('sorting');
$sorting = $this->sortHelper->retrieveSorting($sorting);
$size = $request->query->getInt('limit', 3);
$size = $request->query->getInt('limit', $this->taxonDefaultPageLimit);
$page = $request->query->getInt('page', 1);

/** @var array<string, array<string, string>> $requestFilters */
Expand Down

0 comments on commit 1e05088

Please sign in to comment.