Browse Source

Allow URL #hash for scoped paginator links

Edgaras Janušauskas 8 years ago
parent
commit
72cbe47abd

+ 6 - 0
src/View/Helper/PaginatorHelper.php

@@ -553,6 +553,12 @@ class PaginatorHelper extends Helper
         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];

+ 4 - 0
tests/TestCase/View/Helper/PaginatorHelperTest.php

@@ -910,6 +910,10 @@ class PaginatorHelperTest extends TestCase
         $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);
     }
 
     /**