From b5554700c632ecc9ec4604b0ae5e5964edb2e0eb Mon Sep 17 00:00:00 2001 From: Jim Safley Date: Thu, 4 Apr 2024 13:59:37 -0400 Subject: [PATCH 1/2] Add options to pagination helper; add ability to change the page key --- application/src/View/Helper/Pagination.php | 12 ++++++++++-- application/view/common/linked-resources.phtml | 2 +- application/view/common/pagination.phtml | 2 +- application/view/omeka/admin/item/show.phtml | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/application/src/View/Helper/Pagination.php b/application/src/View/Helper/Pagination.php index b767c22d4..99f368ab7 100644 --- a/application/src/View/Helper/Pagination.php +++ b/application/src/View/Helper/Pagination.php @@ -31,6 +31,8 @@ class Pagination extends AbstractHelper */ protected $fragment; + protected $options; + /** * Construct the helper. * @@ -44,14 +46,18 @@ public function __construct(Paginator $paginator) /** * Configure the pagination. * + * Options: + * - page_key: The page # key passed in the URL query (defualt: "page") + * * @param string|null $partialName Name of view script * @param int|null $totalCount The total record count * @param int|null $currentPage The current page number * @param int|null $perPage The number of records per page + * @param array $options * @return self */ public function __invoke($partialName = null, $totalCount = null, $currentPage = null, - $perPage = null + $perPage = null, array $options = [] ) { if (null !== $totalCount) { $this->getPaginator()->setTotalCount($totalCount); @@ -63,6 +69,7 @@ public function __invoke($partialName = null, $totalCount = null, $currentPage = $this->getPaginator()->setPerPage($perPage); } $this->partialName = $partialName ?: self::PARTIAL_NAME; + $this->options = $options; return $this; } @@ -99,6 +106,7 @@ public function __toString() 'lastPageUrl' => $this->getUrl($pageCount), 'pagelessUrl' => $this->getPagelessUrl(), 'offset' => $paginator->getOffset(), + 'options' => $this->options, ] ); } @@ -127,7 +135,7 @@ public function setFragment($fragment) protected function getUrl($page) { $query = $this->getView()->params()->fromQuery(); - $query['page'] = (int) $page; + $query[$this->options['page_key'] ?? 'page'] = (int) $page; if (isset($query['sort_by_default'])) { // Do not emit sort_by if the sort_by_default flag is set. unset($query['sort_by']); diff --git a/application/view/common/linked-resources.phtml b/application/view/common/linked-resources.phtml index 72cf01cc2..c7b63e541 100644 --- a/application/view/common/linked-resources.phtml +++ b/application/view/common/linked-resources.phtml @@ -2,7 +2,7 @@ use Laminas\Form\Element\Select; // Set up pagination. -$pagination = $this->pagination(null, $totalCount, $page, $perPage); +$pagination = $this->pagination(null, $totalCount, $page, $perPage, ['page_key' => 'linked_resources_page']); $fragment = 'resources-linked'; $pagination->setFragment($fragment); diff --git a/application/view/common/pagination.phtml b/application/view/common/pagination.phtml index dea64cc19..097a6019e 100644 --- a/application/view/common/pagination.phtml +++ b/application/view/common/pagination.phtml @@ -12,7 +12,7 @@ if (isset($query['sort_by_default'])) {
queryToHiddenInputs($removeQueries); ?> - aria-label=""> + aria-label="">
diff --git a/application/view/omeka/admin/item/show.phtml b/application/view/omeka/admin/item/show.phtml index 072c009de..2998cc699 100644 --- a/application/view/omeka/admin/item/show.phtml +++ b/application/view/omeka/admin/item/show.phtml @@ -40,7 +40,7 @@ $itemMedia = $item->media();
subjectValueTotalCount()): ?> displaySubjectValues([ - 'page' => $this->params()->fromQuery('page', 1), + 'page' => $this->params()->fromQuery('linked_resources_page', 1), 'perPage' => 25, 'resourceProperty' => $this->params()->fromQuery('resource_property'), ]); ?> From dc214c247b30ded572c9099a97ae72c9a6eb784c Mon Sep 17 00:00:00 2001 From: Jim Safley Date: Thu, 4 Apr 2024 14:11:15 -0400 Subject: [PATCH 2/2] Fix unit test --- application/test/OmekaTest/View/Helper/PaginationTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/test/OmekaTest/View/Helper/PaginationTest.php b/application/test/OmekaTest/View/Helper/PaginationTest.php index e36fe19f3..29331de90 100644 --- a/application/test/OmekaTest/View/Helper/PaginationTest.php +++ b/application/test/OmekaTest/View/Helper/PaginationTest.php @@ -82,6 +82,7 @@ public function testToString() 'lastPageUrl' => null, 'pagelessUrl' => null, 'offset' => null, + 'options' => [], ]) ) ->will($this->returnValue(''));