Skip to content

Commit

Permalink
Fix limit of list
Browse files Browse the repository at this point in the history
  • Loading branch information
e-spin committed Nov 15, 2023
1 parent 489a86b commit f13ce08
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/Panel/DefaultLimitElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ class DefaultLimitElement extends AbstractElement implements LimitElementInterfa
*
* @var int
*/
private $intOffset = 0;
private int $intOffset = 0;

/**
* The current amount.
*
* @var int
*/
private $intAmount = 0;
private int $intAmount = 0;

/**
* The total amount of all valid entries.
*
* @var int
*/
private $intTotal = 0;
private int $intTotal = 0;

/**
* Retrieve the amount of items to display per page.
Expand Down Expand Up @@ -176,8 +176,10 @@ public function initialize(ConfigInterface $config, PanelElementInterface $eleme

$this->defineOffsetAndAmountOption($offset, $amount);

$config->setStart($this->getOffset());
$config->setAmount($this->getAmount());
$this->setOffset($offset);
$this->setAmount($amount);
$config->setStart($offset);
$config->setAmount($amount);
}

/**
Expand All @@ -190,21 +192,25 @@ public function initialize(ConfigInterface $config, PanelElementInterface $eleme
*/
private function defineOffsetAndAmountOption(int &$offset, int &$amount): void
{
$inputProvider = $this->getEnvironment()->getInputProvider();
assert($inputProvider instanceof InputProviderInterface);

if ('1' === $inputProvider->getValue('filter_reset')) {
$input = $this->getInputProvider();
if ('1' === $input->getValue('filter_reset')) {
$this->setPersistent(0, 0);

return;
}
$input = $this->getInputProvider();
if ($input->hasValue('tl_limit') && $this->getPanel()->getContainer()->updateValues()) {

if ($input->hasValue('tl_limit') && $this->getPanel()?->getContainer()->updateValues()) {
$limit = $input->getValue('tl_limit');
if ('tl_limit' !== $limit) {
[$offset, $amount] = \explode(',', $input->getValue('tl_limit')) + [0, 0];
$this->setPersistent((int) $offset, (int) $amount);
if ('all' === $limit) {
$offset = 0;
$amount = $this->getAmountForFilterOptionAll();
$this->setPersistent($offset, $amount);
return;
}
[$offset, $amount] = \explode(',', $input->getValue('tl_limit')) + [0, 0];
$offset = (int) $offset;
$amount = (int) $amount;
$this->setPersistent($offset, $amount);
}

$persistent = $this->getPersistent();
Expand All @@ -217,11 +223,6 @@ private function defineOffsetAndAmountOption(int &$offset, int &$amount): void
if ($offset > $this->intTotal) {
$offset = 0;
}

if ('all' === $offset) {
$offset = 0;
$amount = $this->getAmountForFilterOptionAll();
}
}
}

Expand All @@ -230,7 +231,7 @@ private function defineOffsetAndAmountOption(int &$offset, int &$amount): void
*
* @return int
*/
private function getAmountForFilterOptionAll()
private function getAmountForFilterOptionAll(): int
{
return $this->intTotal > $this->getMaxItemsPerPage() ? $this->getMaxItemsPerPage() : $this->intTotal;
}
Expand Down

0 comments on commit f13ce08

Please sign in to comment.