Skip to content

Commit

Permalink
Safely get the next and previous page numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed May 30, 2024
1 parent 5bd3ff6 commit 42c9f2d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ public function __construct()
* @param PaginatorInterface $paginator
* @return array
*/
//TODO: clean this function
protected function buildSimplePagination(PaginationInterface $pagination, PaginatorInterface $paginator): array
{
$firstPage = $pagination->getFirstPageNumber();
Expand Down Expand Up @@ -406,8 +407,9 @@ protected function buildSimplePagination(PaginationInterface $pagination, Pagina
array_push($pagesSect, ['label' => '...', 'startRecordNumber' => '...']);
};

$nextPageNumber = $pages[$currentPageNumber + 1]['startRecordNumber'];
$previousPageNumber = $pages[$currentPageNumber - 1]['startRecordNumber'];
// Safely get the next and previous page numbers
$nextPageNumber = isset($pages[$currentPageNumber + 1]['startRecordNumber']) ? $pages[$currentPageNumber + 1]['startRecordNumber'] : null;
$previousPageNumber = isset($pages[$currentPageNumber - 1]['startRecordNumber']) ? $pages[$currentPageNumber - 1]['startRecordNumber'] : null;

// 'startRecordNumber' is not required in GridView, only the variant for each loop is required
// 'endRecordNumber' is not required in both views
Expand Down

0 comments on commit 42c9f2d

Please sign in to comment.