From 72cbe47abd5167c936671e566067609d587c5021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgaras=20Janu=C5=A1auskas?= Date: Sat, 6 Jan 2018 21:48:57 +0200 Subject: [PATCH] Allow URL #hash for scoped paginator links --- src/View/Helper/PaginatorHelper.php | 6 ++++++ tests/TestCase/View/Helper/PaginatorHelperTest.php | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/View/Helper/PaginatorHelper.php b/src/View/Helper/PaginatorHelper.php index 07c654cd1fc..afca1b64086 100644 --- a/src/View/Helper/PaginatorHelper.php +++ b/src/View/Helper/PaginatorHelper.php @@ -553,6 +553,12 @@ public function generateUrlParams(array $options = [], $model = null) if (!empty($paging['scope'])) { $scope = $paging['scope']; $currentParams = $this->_config['options']['url']; + + if (isset($url['#'])) { + $currentParams['#'] = $url['#']; + unset($url['#']); + } + // Merge existing query parameters in the scope. if (isset($currentParams['?'][$scope]) && is_array($currentParams['?'][$scope])) { $url += $currentParams['?'][$scope]; diff --git a/tests/TestCase/View/Helper/PaginatorHelperTest.php b/tests/TestCase/View/Helper/PaginatorHelperTest.php index cd3f3f99fa0..237d6f92e9f 100644 --- a/tests/TestCase/View/Helper/PaginatorHelperTest.php +++ b/tests/TestCase/View/Helper/PaginatorHelperTest.php @@ -910,6 +910,10 @@ public function testGenerateUrlMultiplePagination() $result = $this->Paginator->generateUrl(['sort' => 'name']); $expected = '/posts/index?article%5Bpage%5D=3&article%5Bsort%5D=name'; $this->assertEquals($expected, $result); + + $result = $this->Paginator->generateUrl(['#' => 'foo']); + $expected = '/posts/index?article%5Bpage%5D=3#foo'; + $this->assertEquals($expected, $result); } /**