Browse Source

Merge pull request #12197 from cakephp/3.6-add-dep-paginator

3.6 - deprecationWarning - PaginatorHelper::generateUrl()
Mark Story 7 years ago
parent
commit
0df0fcd53f

+ 13 - 7
src/View/Helper/PaginatorHelper.php

@@ -494,14 +494,20 @@ class PaginatorHelper extends Helper
      *
      * @param array $options Pagination/URL options array
      * @param string|null $model Which model to paginate on
-     * @param array|bool $urlOptions Array of options or bool `fullBase` for BC reasons.
+     * @param array $urlOptions Array of options
+     * The bool version of this argument is *deprecated* and will be removed in 4.0.0
      * @return string By default, returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)
      * @link https://book.cakephp.org/3.0/en/views/helpers/paginator.html#generating-pagination-urls
      */
-    public function generateUrl(array $options = [], $model = null, $urlOptions = false)
+    public function generateUrl(array $options = [], $model = null, $urlOptions = [])
     {
-        if (!is_array($urlOptions)) {
+        if (is_bool($urlOptions)) {
             $urlOptions = ['fullBase' => $urlOptions];
+            deprecationWarning(
+                'Passing a boolean value as third argument into PaginatorHelper::generateUrl() is deprecated ' .
+                'and will be removed in 4.0.0 . ' .
+                'Pass an array instead.'
+            );
         }
         $urlOptions += [
             'escape' => true,
@@ -1142,19 +1148,19 @@ class PaginatorHelper extends Helper
         $links = [];
 
         if ($options['prev'] && $this->hasPrev()) {
-            $links[] = $this->Html->meta('prev', $this->generateUrl(['page' => $params['page'] - 1], null, true));
+            $links[] = $this->Html->meta('prev', $this->generateUrl(['page' => $params['page'] - 1], null, ['fullBase' => true]));
         }
 
         if ($options['next'] && $this->hasNext()) {
-            $links[] = $this->Html->meta('next', $this->generateUrl(['page' => $params['page'] + 1], null, true));
+            $links[] = $this->Html->meta('next', $this->generateUrl(['page' => $params['page'] + 1], null, ['fullBase' => true]));
         }
 
         if ($options['first']) {
-            $links[] = $this->Html->meta('first', $this->generateUrl(['page' => 1], null, true));
+            $links[] = $this->Html->meta('first', $this->generateUrl(['page' => 1], null, ['fullBase' => true]));
         }
 
         if ($options['last']) {
-            $links[] = $this->Html->meta('last', $this->generateUrl(['page' => $params['pageCount']], null, true));
+            $links[] = $this->Html->meta('last', $this->generateUrl(['page' => $params['pageCount']], null, ['fullBase' => true]));
         }
 
         $out = implode($links);

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

@@ -804,10 +804,12 @@ class PaginatorHelperTest extends TestCase
         $this->assertEquals('http://localhost/index?page=3&sort=Article.name&direction=desc', $result);
 
         // @deprecated 3.3.5 Use fullBase array option instead.
-        $this->Paginator->request = $this->Paginator->request->withParam('paging.Article.page', 3);
-        $options = ['sort' => 'Article.name', 'direction' => 'desc'];
-        $result = $this->Paginator->generateUrl($options, null, true);
-        $this->assertEquals('http://localhost/index?page=3&sort=Article.name&direction=desc', $result);
+        $this->deprecated(function () {
+            $this->Paginator->request = $this->Paginator->request->withParam('paging.Article.page', 3);
+            $options = ['sort' => 'Article.name', 'direction' => 'desc'];
+            $result = $this->Paginator->generateUrl($options, null, true);
+            $this->assertEquals('http://localhost/index?page=3&sort=Article.name&direction=desc', $result);
+        });
     }
 
     /**