Skip to content

Commit

Permalink
Merge pull request #1705 from bolt/feature/pager-default-records
Browse files Browse the repository at this point in the history
Pager uses default listing records, if available.
  • Loading branch information
bobdenotter authored Aug 11, 2020
2 parents 538065f + df29d54 commit eb7a628
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Controller/Frontend/ListingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function listing(ContentRepository $contentRepository, string $contentTyp
->setCurrentPage($page);

$templates = $this->templateChooser->forListing($contentType);
$this->twig->addGlobal('records', $records);

$twigVars = [
'records' => $records,
Expand Down
6 changes: 5 additions & 1 deletion src/Twig/ContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,17 @@ public function getListTemplates(TemplateselectField $field): LaravelCollection
return new LaravelCollection($options);
}

public function pager(Environment $twig, Pagerfanta $records, string $template = '@bolt/helpers/_pager_basic.html.twig', string $class = 'pagination', int $surround = 3)
public function pager(Environment $twig, Pagerfanta $records = null, string $template = '@bolt/helpers/_pager_basic.html.twig', string $class = 'pagination', int $surround = 3)
{
$params = array_merge(
$this->request->get('_route_params'),
$this->request->query->all()
);

if (! $records && array_key_exists('records', $twig->getGlobals())) {
$records = $twig->getGlobals()['records'];
}

$context = [
'records' => $records,
'surround' => $surround,
Expand Down

0 comments on commit eb7a628

Please sign in to comment.