Skip to content

Commit

Permalink
Shuffle paginated records
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Valchev committed Jul 16, 2020
1 parent 117629f commit 8311019
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Twig/ArrayExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Bolt\Twig;

use Bolt\Entity\Content;
use Pagerfanta\Pagerfanta;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

Expand All @@ -29,8 +30,12 @@ public function getFilters(): array
/**
* Randomly shuffle the contents of a passed array.
*/
public function shuffle(array $array): array
public function shuffle($array)
{
if ($array instanceof Pagerfanta) {
$array = iterator_to_array($array->getCurrentPageResults());
}

if (is_array($array)) {
shuffle($array);
}
Expand Down

0 comments on commit 8311019

Please sign in to comment.