Skip to content

Commit

Permalink
Add max_per_page filter (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
Prokyonn authored Aug 27, 2024
1 parent 1a8ea28 commit d412072
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Infrastructure/Sulu/Content/ArticleDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getDefaultPropertyParameter(): array

public function resolveDataItems(array $filters, array $propertyParameter, array $options = [], $limit = null, $page = 1, $pageSize = null)
{
[$filters, $sortBy] = $this->resolveFilters($filters, $page, $options['locale']);
[$filters, $sortBy] = $this->resolveFilters($filters, $propertyParameter, $page, $options['locale']);

Check failure on line 75 in src/Infrastructure/Sulu/Content/ArticleDataProvider.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Parameter #4 $locale of method Sulu\Article\Infrastructure\Sulu\Content\ArticleDataProvider::resolveFilters() expects string, mixed given.

$dimensionAttributes = [
'locale' => $options['locale'],
Expand Down Expand Up @@ -105,7 +105,7 @@ public function resolveDataItems(array $filters, array $propertyParameter, array

public function resolveResourceItems(array $filters, array $propertyParameter, array $options = [], $limit = null, $page = 1, $pageSize = null): DataProviderResult
{
[$filters, $sortBy] = $this->resolveFilters($filters, $page, $options['locale']);
[$filters, $sortBy] = $this->resolveFilters($filters, $propertyParameter, $page, $options['locale']);

Check failure on line 108 in src/Infrastructure/Sulu/Content/ArticleDataProvider.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Parameter #4 $locale of method Sulu\Article\Infrastructure\Sulu\Content\ArticleDataProvider::resolveFilters() expects string, mixed given.

$dimensionAttributes = [
'locale' => $options['locale'],
Expand Down Expand Up @@ -134,7 +134,11 @@ public function resolveResourceItems(array $filters, array $propertyParameter, a
return new DataProviderResult($result, $hasNextPage);

Check failure on line 134 in src/Infrastructure/Sulu/Content/ArticleDataProvider.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Parameter #1 $items of class Sulu\Component\SmartContent\DataProviderResult constructor expects array<Sulu\Component\SmartContent\ResourceItemInterface>, array<int<0, max>, array> given.
}

protected function resolveFilters(array $filters, int $page, string $locale): array
/**
* @param array<string, PropertyParameter> $propertyParameter
*/
protected function resolveFilters(
array $filters, array $propertyParameter, int $page, string $locale): array
{
$filter = [
'locale' => $locale,
Expand All @@ -152,8 +156,8 @@ protected function resolveFilters(array $filters, int $page, string $locale): ar
if (isset($filters['tagOperator'])) {
$filter['tagOperator'] = $filters['tagOperator'];
}
if (isset($filters['limitResult'])) {
$filter['limit'] = (int) $filters['limitResult'];
if (isset($filters['limitResult']) || isset($propertyParameter['max_per_page'])) {
$filter['limit'] = (int) ($filters['limitResult'] ?? $propertyParameter['max_per_page']->getValue());
}
$filter['page'] = $page;

Expand Down

0 comments on commit d412072

Please sign in to comment.