Skip to content

Commit

Permalink
[#66] Adds collections support in Util::fillInEntries()
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuapease committed Aug 23, 2023
1 parent 4a1d3a5 commit 0fc7605
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/services/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Craft;
use craft\elements\Entry;
use Illuminate\Support\Collection;

/**
* Various utility services that can be accessed by Twig
Expand All @@ -14,20 +15,24 @@ class Util
* Query for additional, deduped entries to a fill a number
* of needed entries
*
* @param array $entries
* @param array|Collection $entries
* @param array $params
* @param int $limit
* @param array $additionalIdsToSkip
*
* @return array
*/
public static function fillInEntries(
array $entries = [],
array|Collection $entries = [],
array $params = [],
int $limit = 0,
array $additionalIdsToSkip = []
): array
{
if ($entries instanceof Collection) {
$entries = $entries->all();
}

if (!$limit) return [];

$entriesNeeded = $limit - count($entries);
Expand Down

0 comments on commit 0fc7605

Please sign in to comment.